#28210: `<orm_object>._state.adding` behaviour and model inheritance
------------------------------------------+------------------------
               Reporter:  Ivaylo Donchev  |          Owner:  nobody
                   Type:  Uncategorized   |         Status:  new
              Component:  Uncategorized   |        Version:  1.11
               Severity:  Normal          |       Keywords:
           Triage Stage:  Unreviewed      |      Has patch:  0
    Needs documentation:  0               |    Needs tests:  0
Patch needs improvement:  0               |  Easy pickings:  0
                  UI/UX:  0               |
------------------------------------------+------------------------
 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='[email protected]') }}}


 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28210>
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/054.584b2284ef0059b507aa3e7d3c9ba830%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to