factory_boy: factory.Trait() cannot get a factory.RelatedFactory override

Traits does not seem to allow a related factory override.

Ex:

class MyModelFactory(factory.django.DjangoModelFactory):
    class Meta:
          model = models.MyModel
    class Params:
        with_my_other_model = factory.Trait(
             my_other_model=factory.RelatedFactory(MyOtherModelFactory, 'my_model')
        )

It will complain my_other_model is not a valid field.

That would be awesome.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 26 (24 by maintainers)

Commits related to this issue

Most upvoted comments

That’s indeed a bug.

It should be fixed through a partial core refactor which I have started recently 😃

So overriding RelatedFields inside Traits does not work? I think I’ve encountered this, although I’m using sqlalchemy classes.

AttributeError: 'RelatedFactory' object has no attribute '_sa_instance_state'