factory.Trait() cannot get a factory.RelatedFactory override
See original GitHub issueTraits 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.
Issue Analytics
- State:
- Created 7 years ago
- Comments:26 (24 by maintainers)
Top Results From Across the Web
Reference — Factory Boy stable documentation
The Factory class provides a few methods for getting objects; the usual way being to simply ... Values set in a Trait can...
Read more >Django + Factory Boy: How to use a named parameter to ...
It seems that factory boy have a feature to provided additional parameters without having to add theses fields to the exclude attribute: ...
Read more >Factory Boy Documentation - Read the Docs
That policy will be used if the associated class has an objects attribute and the _create() classmethod of the Factory wasn't overridden.
Read more >factory-boy Changelog - pyup.io
- Fix issue with overriding parameters in a Trait, thanks `Grégoire Rocher <https://github.com/cecedille1>`_. - :issue:`598`: Limit ``get_or_create`` behavior ...
Read more >Test factory functions in Django - lukeplant.me.uk
It doesn't break type checking for the functions calling our factory functions. Constraints and sequences. Often you have the problem that a ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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.