#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.

-- 
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/048.00500290009587cbf081eb74a4b4148b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to