ManyToMany relationships referencing 'self' choke when the model has a non null foreign key
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Django Factory |
Fix Released
|
High
|
James Westby |
Bug Description
models:
class Group(models.
name = models.
class Member(
group = models.
name = models.
friends = models.
>>> from django_factory import Factory
>>> f = Factory()
>>> from testapp.models import Member
>>> m = f.make_one(Member)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/vagrant/
return self._create_
File "/vagrant/
instance, m2m_dict, fk_dict = self._generate_
File "/vagrant/
model, field, not_including, attrs)
File "/vagrant/
not_including + [model], {}))
File "/vagrant/
instance.save()
File "/usr/lib/
self.
File "/usr/lib/
result = manager.
File "/usr/lib/
return insert_
File "/usr/lib/
return query.execute_
File "/usr/lib/
cursor = super(InsertQuery, self).execute_
File "/usr/lib/
cursor.
File "/usr/lib/
return self.cursor.
IntegrityError: null value in column "group_id" violates not-null constraint
What happens is that the member is created, a group is created, and that's fine. Then a member is created to get test data in to the 'friends' field, but none of the foreignkeys are used when generating the member for 'friends'.
Changed in django-factory: | |
milestone: | none → 0.7 |
status: | Fix Committed → Fix Released |
Hi, nice bug. The loop detection was broken (over eager) and so it was skipping
the ForeignKey as you identified.
I've fixed the loop detection so it only skips the ForeignKey if it is really part
of a loop.
Thanks,
James