RelatedManager.add fails silently when adding an object of the wrong type
When trying to add an object of the wrong type using a related manager, Django fails silently rather than complaining as specified in the docs:
http://docs.djangoproject.com/en/dev/topics/db/queries/#saving-foreignkey-and-manytomanyfield-fields
Example:
class ParentModel(models.Model):
name = models.CharField(max_length=200)
class ChildModel(models.Model):
name = models.CharField(max_length=200)
parent = models.ForeignKey(ParentModel, related_name="child_models")
class NotAChildModel(models.Model):
name = models.CharField(max_length=200)
p = ParentModel(name='Parent')
p.save()
nc = NotAChildModel(name='Not A Child')
nc.save()
p.child_models.add(nc) # This should blow up, but doesn't
p.child_models.all() # Returns []
Change History
(9)
milestone: |
→ 1.1
|
Triage Stage: |
Unreviewed → Accepted
|
Component: |
Uncategorized → Database layer (models, ORM)
|
Cc: |
dgouldin@… added
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
Updated patch to move import of Model class into ManyRelatedManager._add_items.