Opened 8 years ago
Last modified 8 years ago
#28210 closed Bug
`<orm_object>._state.adding` behaviour and model inheritance — at Initial Version
Reported by: | Ivaylo Donchev | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.11 |
Severity: | Release blocker | Keywords: | |
Cc: | Simon Charette | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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:
admin = Admin.objects.create(email='admin@admin.com')
This will create an Admin instance and User instance, with admin.user_ptr._state.adding == True
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.