[Django] #27967: The autogenerated OneToOneField on multi table inheritance breaks the InlineAdminForm given UUID pk

14 views
Skip to first unread message

Django

unread,
Mar 20, 2017, 10:40:22 PM3/20/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-----------------------------------------+------------------------
Reporter: Robin Anupol | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Keywords: admin
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
I'm receiving MultiValueDictKeyError given the following setup:
{{{
# models.py
class A(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
editable=False)
name = models.CharField(max_length=32)

class B(A):
s = models.ForeignKey('S', models.PROTECT)

class S(models.Model):
name = models.CharField(max_length=32)

# admin.py
class BInline(admin.StackedInline):
model = B

@admin.register(S)
class SAdmin(admin.ModelAdmin):
inlines = [BInline]
}}}
To get the error:
1. On admin page, create an S instance.
2. On S instance, create 1 B inline instance then save.
3. Still on S instance, create another B inline instance then save.

Here's the trace:

{{{
Traceback (most recent call last):
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/core/handlers/exception.py", line 42, in inner
response = get_response(request)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/contrib/admin/options.py", line 544, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/contrib/admin/sites.py", line 211, in inner
return view(request, *args, **kwargs)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/contrib/admin/options.py", line 1512, in change_view
return self.changeform_view(request, object_id, form_url,
extra_context)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/utils/decorators.py", line 185, in inner
return func(*args, **kwargs)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/contrib/admin/options.py", line 1448, in changeform_view
if all_valid(formsets) and form_validated:
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/forms/formsets.py", line 456, in all_valid
if not formset.is_valid():
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/forms/formsets.py", line 321, in is_valid
self.errors
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/forms/formsets.py", line 295, in errors
self.full_clean()
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/forms/formsets.py", line 343, in full_clean
form = self.forms[i]
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/forms/formsets.py", line 144, in forms
for i in range(self.total_form_count())]
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/forms/models.py", line 896, in _construct_form
form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs)
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/forms/models.py", line 593, in _construct_form
pk = self.data[pk_key]
File "/home/rnddev/.virtualenvs/vulcan/local/lib/python2.7/site-
packages/django/utils/datastructures.py", line 85, in __getitem__
raise MultiValueDictKeyError(repr(key))
MultiValueDictKeyError: "u'b_set-0-a_ptr'"
}}}

More info:
The error presents itself under both SQLite and PostgreSQL.
If the id of the parent A is the default AutoField, there's no error.
I specified InlineAdminForm because there's a relevant check there
(method: needs_explicit_pk_field) that might be the issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/27967>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 20, 2017, 10:50:23 PM3/20/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+--------------------------------------

Reporter: Robin Anupol | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:

Keywords: admin | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Robin Anupol):

* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:1>

Django

unread,
Mar 21, 2017, 7:08:47 AM3/21/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+------------------------------------------
Reporter: Robin Anupol | Owner: Vedran Karačić
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:

Keywords: admin | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------------
Changes (by Vedran Karačić):

* status: new => assigned
* owner: nobody => Vedran Karačić
* cc: vedran@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:2>

Django

unread,
Mar 23, 2017, 7:43:02 PM3/23/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+------------------------------------------
Reporter: Robin Anupol | Owner: Vedran Karačić
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:
Keywords: admin | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------------
Changes (by Tim Graham):

* easy: 1 => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:3>

Django

unread,
Apr 3, 2017, 2:59:14 PM4/3/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+------------------------------------
Reporter: Robin Anupol | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10

Severity: Normal | Resolution:
Keywords: admin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Vedran Karačić):

* status: assigned => new
* cc: vedran@… (removed)
* owner: Vedran Karačić => (none)


--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:4>

Django

unread,
Apr 3, 2017, 8:33:47 PM4/3/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+------------------------------------
Reporter: Robin Anupol | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10

Severity: Normal | Resolution:
Keywords: admin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Robin Anupol):

As a workaround, on the app's admin.py, I have this prepended:
{{{
# admin.py
from django.contrib.admin.helpers import InlineAdminForm

def needs_explicit_pk_field(self):
# original definition goes here
# place this conditional right before the end of the function
if self.form._meta.model._meta.pk.auto_created:
return True
return False

InlineAdminForm.needs_explicit_pk_field = needs_explicit_pk_field

from django.contrib import admin
# the rest of admin.py goes here.
}}}

This works for me but I'm not sure of any edge cases associated with the
auto_created attribute.

--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:5>

Django

unread,
Apr 7, 2017, 6:04:01 AM4/7/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+------------------------------------
Reporter: Robin Anupol | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10

Severity: Normal | Resolution:
Keywords: admin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Marco Silva):

added a test that reproduces the error, I think....

wip here
https://github.com/marco-silva0000/django/tree/27967-inline-uuid-breaks

--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:6>

Django

unread,
Apr 7, 2017, 7:38:43 AM4/7/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+------------------------------------
Reporter: Robin Anupol | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 1.10

Severity: Normal | Resolution:
Keywords: admin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by oyooyo):

I wonder if this bug is somehow related to #27595
The description reads different, it is said to occur in both PostgreSQL
and SQLite - but just like #27595, the issue seems to somehow be related
to multi-table inheritance with UUIDFields as primary keys.

--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:7>

Django

unread,
Jun 9, 2017, 8:09:01 PM6/9/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+------------------------------------
Reporter: Robin Anupol | Owner: Paulo
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.10

Severity: Normal | Resolution:
Keywords: admin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Paulo):

* owner: (none) => Paulo


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:8>

Django

unread,
Jun 9, 2017, 9:03:06 PM6/9/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+------------------------------------
Reporter: Robin Anupol | Owner: Paulo
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.10

Severity: Normal | Resolution:
Keywords: admin | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Paulo):

* has_patch: 0 => 1


Comment:

PR https://github.com/django/django/pull/8623

--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:9>

Django

unread,
Jun 12, 2017, 9:33:07 PM6/12/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+------------------------------------
Reporter: Robin Anupol | Owner: Paulo
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution: fixed

Keywords: admin | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"9dc83c356d363c090f3351c908cad6f823aeb7bf" 9dc83c35]:
{{{
#!CommitTicketReference repository=""
revision="9dc83c356d363c090f3351c908cad6f823aeb7bf"
Fixed #27967 -- Fixed KeyError in admin's inline form with inherited non-
editable pk.

Thanks Robin Anupol for the initial report and workaround.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:10>

Django

unread,
Jun 12, 2017, 9:33:29 PM6/12/17
to django-...@googlegroups.com
#27967: The autogenerated OneToOneField on multi table inheritance breaks the
InlineAdminForm given UUID pk
-------------------------------+------------------------------------
Reporter: Robin Anupol | Owner: Paulo
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.10

Severity: Normal | Resolution: fixed
Keywords: admin | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"927d9b51fee2442280ae975b21b98b5a705c4b17" 927d9b51]:
{{{
#!CommitTicketReference repository=""
revision="927d9b51fee2442280ae975b21b98b5a705c4b17"
[1.11.x] Fixed #27967 -- Fixed KeyError in admin's inline form with
inherited non-editable pk.

Thanks Robin Anupol for the initial report and workaround.

Backport of 9dc83c356d363c090f3351c908cad6f823aeb7bf from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27967#comment:11>

Reply all
Reply to author
Forward
0 new messages