Fixes #20542: Add form prefix to POST
handler in ObjectEditView
#20550
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #20542
Commit d222466 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 thequickadd-
prefix duringGET
requests, but thePOST
handler instantiated forms without the prefix. When users submitted quick add forms, Django looked for unprefixed field names likeaddress
andstatus
in thePOST
data, but the actual submitted data used prefixed names likequickadd-address
andquickadd-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 theGET
handler, checking for the_quickadd
parameter in the query string and applying thequickadd
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.