RelatedFactory parametrs #58

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

Comments

Projects
None yet
2 participants
@kwist-sgr

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

This comment has been minimized.

Show comment
Hide comment
@rbarrois

rbarrois Apr 29, 2013

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'
Member

rbarrois commented Apr 29, 2013

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

declarations: Rename RelatedFactory.name (See #58).
Use less conflict-prone factory_related_name.

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

This comment has been minimized.

Show comment
Hide comment
@rbarrois

rbarrois Jun 26, 2013

Member

This should be fixed in the v2.1.0 release.

Member

rbarrois commented Jun 26, 2013

This should be fixed in the v2.1.0 release.

@rbarrois rbarrois closed this Jun 26, 2013

@kwist-sgr

This comment has been minimized.

Show comment
Hide comment
@kwist-sgr

kwist-sgr Jul 2, 2013

Thank you for the update. Now its working fine.

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