klen / mixer

Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.
Other
944 stars 95 forks source link

Infinite loop if model includes more than one relations to self #197

Open kosdmit opened 3 months ago

kosdmit commented 3 months ago

backend: mixer.backend.django

I get an infinite loop then I try to create objects for model with two ForeignKey fields and relation to self.

For example:
command mixer.blend(SAPDepartment) with the model:

class SAPDepartment(models.Model):
    sap_name = models.CharField(max_length=150, null=False, blank=False)
    sap_id = models.IntegerField()
    upper_dep = models.ForeignKey('self', related_name='low_dep', on_delete=models.SET_NULL, null=True)
    main_dep = models.ForeignKey('self', related_name='main_department', on_delete=models.SET_NULL, null=True)