#28210: `<orm_object>._state.adding` behaviour and model inheritance -------------------------------------+------------------------------------- Reporter: Ivaylo Donchev | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.11 (models, ORM) | 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 -------------------------------------+-------------------------------------
Old description: > Let's say we have the following models: > {{{ > class User(models.Model): > email = models.CharField(max_length=255, unique=True) > password = models.CharField(max_length=32, > widget=forms.PasswordInput) > > class Admin(User): > pass > > class ThirdPartyUser(User): > pass > }}} > > Steps to reproduce: > 1. {{{ admin = Admin.objects.create(email='ad...@admin.com') }}} > > This will create an Admin instance and User instance, with > `admin.user_ptr._state.adding == True` > > 2. {{{ ThirdPartyUser.objects.create(user_ptr = admin.user_ptr) }}} > > This will raise the following error `{'email': ['User with this Email > address already exists.'], 'id': ['User with this ID already exists.'] }` > When the admin is created, the `admin.user_ptr._state.adding` is True, > but admin._state.adding is False (as it is already created). > If we set {{{ admin.user_ptr._state.adding = False }}}, step 2 is passing > without errors. New description: Let's say we have the following models: {{{ class User(models.Model): email = models.CharField(max_length=255, unique=True) password = models.CharField(max_length=32) class Admin(User): pass class ThirdPartyUser(User): pass }}} Steps to reproduce: 1. {{{ admin = Admin.objects.create(email='ad...@admin.com') }}} This will create an Admin instance and User instance, with `admin.user_ptr._state.adding == True` 2. {{{ ThirdPartyUser.objects.create(user_ptr = admin.user_ptr) }}} This will raise the following error `{'email': ['User with this Email address already exists.'], 'id': ['User with this ID already exists.'] }` When the admin is created, the `admin.user_ptr._state.adding` is True, but admin._state.adding is False (as it is already created). If we set {{{ admin.user_ptr._state.adding = False }}}, step 2 is passing without errors. -- Comment (by Tim Graham): I can't reproduce using the steps described in the description. How does `ThirdPartyUser.objects.create()` raise a dictionary? Please clarify. -- Ticket URL: <https://code.djangoproject.com/ticket/28210#comment:6> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.1f5787d62f31a7e296f507d3d0f49a75%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.