Fixes #567: Make "Custom object type" field read-only in Add Field flow#568
Fixes #567: Make "Custom object type" field read-only in Add Field flow#568bctiemann wants to merge 4 commits into
Conversation
TomSelect uses LABEL_FIELD='display' to look up the display name for options fetched from the API. CustomObjectTypeSerializer.Meta.fields never included 'display', so preloaded options came back with no display value, causing TomSelect to show 'undefined' as the selected item label when the custom_object_type dropdown was clicked on the Add Field form. Adding 'display' to the field list makes the COT API return str(obj) as the display name, which TomSelect uses correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
custom_object_type has never been meaningful to edit in either flow: - Add: the COT is always pre-set from the URL param (?custom_object_type=N) - Edit: the field was already disabled Making it unconditionally disabled also eliminates the 'undefined' label in the TomSelect dropdown: a disabled APISelect is rendered as a static display widget, so TomSelect never preloads from the API and never overwrites the DOM-parsed label with the missing 'display' field. Update form tests to pass custom_object_type via initial= (not data=) to match disabled-field semantics. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lter_object Disabled form fields use the instance value (not POST data) as their cleaned_data value. The generic view's POST handler only passes data=request.POST to the form — no initial. For a new CustomObjectTypeField, the instance has no custom_object_type_id yet, so cleaned_data['custom_object_type'] was missing, causing KeyError in clean_primary(). Override alter_object() to pre-populate custom_object_type_id from the URL query param (?custom_object_type=N) for new objects. This makes the disabled field behave correctly for both GET (display) and POST (save). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The generic view test harness (PrimaryObjectViewTestCase) posts form_data in the request body rather than as a URL query param. Fall back to request.POST so that test POSTs without a GET param also work correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@claude /review |
|
Claude finished @bctiemann's task in 4m 19s —— View job Code Review — PR #568
OverviewThis PR addresses issue #567 via two complementary strategies: (1) adding The overall approach is correct and well-structured across 4 commits. A few observations below.
|
| Item | Verdict |
|---|---|
display fix for TomSelect |
✅ Correct |
Always-disabled custom_object_type in form |
✅ Correct |
alter_object GET-param reading |
✅ Correct |
alter_object POST-body reading |
✅ Pragmatic, minor authorization note above |
| Test update for disabled field | ✅ Correct |
display missing from brief_fields |
The changes are solid. The one clear improvement would be adding "display" to brief_fields for consistency.
|
The agent review looks like it is keying on the initial commit which added |
Fixes: #567
Summary
The Custom object type dropdown on the Add Field form showed
undefinedas the selected value when clicked.Root Cause
TomSelect (NetBox's select widget) uses
LABEL_FIELD = 'display'to resolve option labels from API results.CustomObjectTypeSerializer.Meta.fieldsnever included"display", so the Custom Object Type API endpoint returned objects without a display value. When TomSelect preloaded options on focus, it overwrote the DOM-parsed label withundefined, causing the displayed selection to change to the literal string "undefined".However, there is no need for this field to be editable in the first place, and it is disabled/read-only in the Edit flow for an existing Custom Object Type Field. The real root cause is that the field should be read-only and inferred from the COT context in the Add flow too.
Fix
Make
custom_object_typeread-only and inferred from the view context when creating a new Custom Object Type Field.🤖 Generated with Claude Code