berinhard/model_mommy

Can't provide override for field named "model"

robertfw opened this issue · 2 comments

I have a model which has a field named "model". Trying to override it when creating using make() clashes with the first model argument.

e.g.

class Example(models.Model):
    model = models.TextField()

mommy.make(Example, model='Something')

>> TypeError: make() got multiple values for argument 'model'

This could be fixed by modifying make() to allow passing overrides as a dictionary instead of as kwargs, eg

def make(model, _quantity=None, make_m2m=False, _save_kwargs=None, defaults=None, **attrs):
    if defaults is not None:
        attrs.update(defaults)
    # .....


mommy.make(Example, defaults={'model': 'Something'})
>> <Example: Example object>

Thanks for your report @robertfw - This seems an extreme edge case that fixing it will either clutter the API (defaults) or breaking compatibility:

def make(model_ ...):

Sorry, but i'm willing to close this one as wontfix - @berinhard - what are your thoughts?

@vandersonmota I agree with you about it. It's a very specific edge case and to support it we'll have to introduce some serious compatibility warnings.