Opened 9 years ago

Closed 8 years ago

#3849 closed (duplicate)

Saving edit_inline OneToOneField is broken in admin

Reported by: Ilya Semenov <semenov@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: OneToOneField admin edit_inline
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Consider the following model:

class UserProfile(models.Model):
    user = OneToOneField(User, edit_inline=models.TABULAR)
    data = models.CharField(maxlength=255, core=True)

Saving a user object in admin interface produces the following error:

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/django/core/handlers/", line 77, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/", line 55, in _checklogin
    return view_func(request, *args, **kwargs)
  File "/usr/lib/python2.4/site-packages/django/views/decorators/", line 39, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/", line 329, in change_stage
    new_object =
  File "/usr/lib/python2.4/site-packages/django/db/models/", line 165, in save
    if rel_new_data[][0]:
KeyError: 'user'

Note: this is not the problem with OneToOneField related object not created. The related object already exists in the database.

I know this ticket will probably be considered "invalid" in favour of upcoming admin rewrite, but I'm still going to submit the patch (against revision [4835]) for those who don't have time to wait for the new admin and just want their system working.

Attachments (2)

onetoonefield-edit_inline.patch (999 bytes) - added by Ilya Semenov <semenov@…> 9 years ago.
onetoonefield-edit_inline-related.patch (847 bytes) - added by simon@… 9 years ago.
this additional patch seems to be required too

Download all attachments as: .zip

Change History (5)

Changed 9 years ago by Ilya Semenov <semenov@…>

comment:1 Changed 9 years ago by simon@…

  • Component changed from Metasystem to Database wrapper
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Thanks Ilya, your patch fixed the saving problem, but seemed to break admin when there was no existing related record. I'm attaching a patch for this too (note to others: you probably want both these patches).

Changed 9 years ago by simon@…

this additional patch seems to be required too

comment:2 Changed 9 years ago by simon@…

Further testing reveals 'EmptyQuerySet' object has no attribute '_collect_sub_objects' - I'm going to stop using OneToOneField and use ForeignKey instead for now...

comment:3 Changed 8 years ago by ubernostrum

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #24.

Note: See TracTickets for help on using tickets.
Back to Top