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
- Merge pull request #1 from FactoryBoy/rbarrois/fix-351 Fix trait-related issues found in #351 / #373 — committed to jrobichaud/factory_boy by jrobichaud 7 years ago
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.