question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
rbarroiscommented, Feb 25, 2017

That’s indeed a bug.

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

1reaction
HeyHugocommented, Jan 7, 2018

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'
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found