Fixes #20542: Add form prefix to POST handler in ObjectEditView #1092

Closed
opened 2026-04-05 20:34:47 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @jnovinger on 10/9/2025

Fixes: #20542

Commit d22246688 added form prefix support to the GET handler to fix Markdown preview functionality in quick add modals. The form prefix allows Django to properly namespace field names and IDs when rendering forms within the quick add modal context.

However, the corresponding change was not made to the POST handler. This created a mismatch where form fields were rendered with the quickadd- prefix during GET requests, but the POST handler instantiated forms without the prefix. When users submitted quick add forms, Django looked for unprefixed field names like address and status in the POST data, but the actual submitted data used prefixed names like quickadd-address and quickadd-status. This caused validation to fail immediately with "This field is required" errors for all required fields, making every quick add form unusable.

The fix adds the same prefix detection logic to the POST handler that was added to the GET handler, checking for the _quickadd parameter in the query string and applying the quickadd prefix when present. This ensures consistent form field naming between rendering and validation.

A regression test has been added to MACAddressTestCase to verify that MAC addresses can be successfully created via the quick add modal, preventing this issue from recurring. This test should be promoted to a template test whenever it becomes possible to determine if a model should support quick-add functionality.

*Originally created by @jnovinger on 10/9/2025* Fixes: #20542 Commit d22246688 added form prefix support to the `GET` handler to fix Markdown preview functionality in quick add modals. The form prefix allows Django to properly namespace field names and IDs when rendering forms within the quick add modal context. However, the corresponding change was not made to the `POST` handler. This created a mismatch where form fields were rendered with the `quickadd-` prefix during `GET` requests, but the `POST` handler instantiated forms without the prefix. When users submitted quick add forms, Django looked for unprefixed field names like `address` and `status` in the `POST` data, but the actual submitted data used prefixed names like `quickadd-address` and `quickadd-status`. This caused validation to fail immediately with "This field is required" errors for all required fields, making every quick add form unusable. The fix adds the same prefix detection logic to the `POST` handler that was added to the `GET` handler, checking for the `_quickadd` parameter in the query string and applying the `quickadd` prefix when present. This ensures consistent form field naming between rendering and validation. A regression test has been added to `MACAddressTestCase` to verify that MAC addresses can be successfully created via the quick add modal, preventing this issue from recurring. This test should be promoted to a template test whenever it becomes possible to determine if a model should support quick-add functionality.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#1092