gregmuellegger/django-autofixture

setting relations using the relation_id generated by django in field_values

ajrouvoet opened this issue · 4 comments

I noticed today that this doesn't work. Nasty, because my tests now failed randomly, which was hard to debug. Is this something that can be fixed?

Can you throw in a little example code as it's a little hard to guess what you mean by the subject :)

Sorry, was in a hurry ;-)

In the following snippet I used to have 'user_id': liduser.pk instead.

AutoFixture(Profiel, field_values={
    'voornaam': 'LID',
    'status': Profiel.STATUS.LID,
    'user': liduser,
}).create(1)

Which I expected to work because that's how django deals with relations usually.

Seems valid. What is the benefit for you to use user_id over user? What happens if you set an integer to the user field? Does that work?

I see the problem you have. But I probably won't get around to fix it soonish. Would you be interested in working on a fix for this?

Setting an integer to the user field is invalid in Django. The benefit is mostly that if you don't have a whole instance, you can still set the related value (without incurring extra costs for getting the instance).

The problem is not that I really want to use this feature though, it's more that it fails very silently and is thus hard to debug. Making it fail obviously by throwing some error would already be a big improvement.