Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RelatedFactory parametrs #58

Closed
kwist-sgr opened this issue Apr 29, 2013 · 3 comments
Closed

RelatedFactory parametrs #58

kwist-sgr opened this issue Apr 29, 2013 · 3 comments
Labels
Milestone

Comments

@kwist-sgr
Copy link

Hi there,

I took this example RelatedFactory and modified it with the "name" field.

Here is my source code:

# models.py
class User(models.Model):
    pass

class UserLog(models.Model):
    user = models.ForeignKey(User)
    name = models.CharField()
    action = models.CharField()


# factories.py
class UserFactory(factory.DjangoModelFactory):
    FACTORY_FOR = models.User

    log = factory.RelatedFactory(UserLogFactory, 'user', name='test', action='create')

This caused the following error:

TypeError: __init__() got multiple values for keyword argument 'name'
@rbarrois
Copy link
Member

That's indeed a nasty bug, due to the fact that the second argument to RelatedFactory is called 'name'.

I'll rename it to "factory_related_name", with deprecation warnings; that might take a couple of releases.

In the meantime, could you see if the following definition works for you:

class UserFactory(factory.DjangoModelFactory):
    FACTORY_FOR = models.User
    log = factory.RelatedFactory(UserLogFactory, 'user', action='create')
    log__name = 'test'

rbarrois added a commit that referenced this issue Apr 29, 2013
Use less conflict-prone factory_related_name.

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
@rbarrois
Copy link
Member

This should be fixed in the v2.1.0 release.

@kwist-sgr
Copy link
Author

Thank you for the update. Now its working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants