django-autofixture icon indicating copy to clipboard operation
django-autofixture copied to clipboard

setting relations using the relation_id generated by django in field_values

Open ajrouvoet opened this issue 9 years ago • 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?

ajrouvoet avatar Jul 10 '15 12:07 ajrouvoet

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

gregmuellegger avatar Jul 10 '15 18:07 gregmuellegger

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.

ajrouvoet avatar Jul 10 '15 18:07 ajrouvoet

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?

gregmuellegger avatar Jul 10 '15 18:07 gregmuellegger

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.

ajrouvoet avatar Jul 11 '15 08:07 ajrouvoet