You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(api): get_form(change=True) for existing objects — detail/update/bulk (#186)
The detail, update (PATCH), and bulk-PATCH views all build the form via
`model_admin.get_form(request, obj=obj)` WITHOUT `change=True`. Django's
own change view always passes `change=not add` (i.e. True for an
existing object — see `ModelAdmin._changeform_view`). A consumer
`get_form` override commonly branches on `change` to return a
change-specific form whose `Meta` omits a *form-only* field (one that
isn't a model field — e.g. an `admin_override` toggle rendered by a
custom form). Called without `change=True`, that override falls through
to `modelform_factory`, which raises
`FieldError: Unknown field(s) (admin_override) ...` → 500.
Observed in the laminr pilot: `GET /admin2/api/v1/package_reviews/
underreviewstatus/<pk>/` 500'd because `UnderReviewStatusAdmin.get_form`
returns its safe `UnderReviewStatusForm` only when `change=True`, else
defers to the default factory which chokes on the form-only
`admin_override` field.
Fix: pass `change=True` at all three existing-object call sites
(detail.py, update.py, bulk.py). create.py is unchanged — it correctly
calls `get_form(obj=None)` with the default `change=False` for the add
path.
Regression test (test_detail.py::test_detail_calls_get_form_with_change_true):
a get_form that raises unless `change=True` for an existing object now
yields a 200; asserts `change=True` was the value seen. 41/41
detail+update+bulk tests pass.
Co-authored-by: Martin Castro Laminrs <mcastro@laminr.ai>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments