#24377: UUIDField as primary key breaks inline admins
---------------------------------+-------------------------------------
Reporter: yoyoma | Owner: timgraham
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------
Changes (by timgraham):
* status: new => assigned
* owner: nobody => timgraham
Comment:
There appear to be a couple problems here:
Since the use of `UUIDField` as a primary key requires
`default=uuid.uuid4`, initializing an object sets its primary key in
[https://github.com/django/django/blob/bed504d70bede3431a213203c13a33905d6dbf77/django/db/models/base.py#L426-L427
Model.__init__()]:
{{{
>>> p = Parent()
>>> p.pk
UUID('cde58b1c-4a5a-471a-901c-6e43847f0a0e')
}}}
That value is then used as the initial value for
[https://github.com/django/django/blob/bed504d70bede3431a213203c13a33905d6dbf77/django/forms/models.py#L931
InlineForeignKeyField] on the inlines. It needs to be ignored since it
will be regenerated on subsequent requests since the field isn't editable
and there's no way to preserve state across requests.
Secondly, the primary key on the inline uses an auto-generated value from
the `default` of the `Child.uuid` field during the save request, but it's
empty on the request for the initial form. This discrepancy causes
`Form.has_changed()` to return `True` which triggers "required" validation
on other fields, even on otherwise empty inlines.
I have a patch that seems to fix these issues and am working on adding
tests.
--
Ticket URL: <https://code.djangoproject.com/ticket/24377#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.0c34d9214e6878eafc7f17730c01ab9b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.