DynamicModelChoice context sometimes fails due to brief=True #9761

Closed
opened 2025-12-29 21:22:14 +01:00 by adam · 2 comments
Owner

Originally created by @samk-acw on GitHub (May 29, 2024).

Deployment Type

Self-hosted

NetBox Version

v4.0.3

Python Version

3.10

Steps to Reproduce

  1. create/edit a form with a DynamicModelChoice field (or custom script with ObjectVar) with context argument to change parent/description
class ExampleForm(NetboxModelForm)
    circuit = DynamicModelChoiceField(
        queryset=Circuit.objects.all(),
        context={
            'parent': 'provider'
            'description': 'type'
        }, 
  1. View the form and check the dropdown

Expected Behavior

Selections in dropdown menu should show the additional context attributes specified (eg. parent to the right, type below the display value)

Observed Behavior

No additional information is shown, the parameters are ignored.
This appears to be due to the use of brief=True to the API calls, but the chosen fields aren't included in the brief data by default.

Manually specifying the additional fields in query_params works around the main problem but this seems like unintended behavior, or at least it should be made clear in the documentation that this step is needed.

Additionally, specifying an object attribute (type in this case) as the 'description' does not work, it's displayed as '[object Object']
image
(this might be considered a different bug, I can raise a separate report if needed)

Originally created by @samk-acw on GitHub (May 29, 2024). ### Deployment Type Self-hosted ### NetBox Version v4.0.3 ### Python Version 3.10 ### Steps to Reproduce 1. create/edit a form with a DynamicModelChoice field (or custom script with ObjectVar) with context argument to change parent/description ``` class ExampleForm(NetboxModelForm) circuit = DynamicModelChoiceField( queryset=Circuit.objects.all(), context={ 'parent': 'provider' 'description': 'type' }, ``` 2. View the form and check the dropdown ### Expected Behavior Selections in dropdown menu should show the additional context attributes specified (eg. parent to the right, type below the display value) ### Observed Behavior No additional information is shown, the parameters are ignored. This appears to be due to the use of brief=True to the API calls, but the chosen fields aren't included in the brief data by default. Manually specifying the additional fields in query_params works around the main problem but this seems like unintended behavior, or at least it should be made clear in the documentation that this step is needed. Additionally, specifying an object attribute (type in this case) as the 'description' does not work, it's displayed as '[object Object'] ![image](https://github.com/netbox-community/netbox/assets/55128650/2477b979-43db-4fc4-bf69-4838d6738eb4) (this might be considered a different bug, I can raise a separate report if needed)
adam closed this issue 2025-12-29 21:22:15 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 29, 2024):

This is not a bug. As with #16311, you are misunderstading how the field works.

Bug reports are to be used only for reporting reproducible, unintended behavior in the core product. As I've already asked, please start a discussion if you need help with custom development.

@jeremystretch commented on GitHub (May 29, 2024): This is not a bug. As with #16311, you are misunderstading how the field works. Bug reports are to be used only for reporting reproducible, unintended behavior in the core product. As I've already asked, please start a [discussion](https://github.com/netbox-community/netbox/discussions/new/choose) if you need help with custom development.
Author
Owner

@samk-acw commented on GitHub (May 30, 2024):

I've created a discussion: https://github.com/netbox-community/netbox/discussions/16347
If you could help enlighten me that would be great because this use case seems consistent with how you described it in the original FR: https://github.com/netbox-community/netbox/issues/13283 (you even mentioned the lack of brief fields, which has since been fixed)

@samk-acw commented on GitHub (May 30, 2024): I've created a discussion: https://github.com/netbox-community/netbox/discussions/16347 If you could help enlighten me that would be great because this use case seems consistent with how you described it in the original FR: https://github.com/netbox-community/netbox/issues/13283 (you even mentioned the lack of brief fields, which has since been fixed)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9761