You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears that when processing SubFactory attributes on the parent factory and generating deps for the SubFactory fixture, the introspected names do not take into account whether a given factory was registered earlier with a different model_name.
I think the root cause of all the issues I'm experiencing can be boiled down to this. This generally shows up when a second factory class is created from a parent subclass. Using the documentation's AuthorFactory as an example:
class BobAuthorFactory(AuthorFactory):
name = "Bob"
register(BobAuthorFactory, "author_bob")
If we create a second BookFactory subclass that uses BobAuthorFactory as the SubFactory:
class BobBookFactory(BookFactory):
author = factory.SubFactory(BobAuthorFactory)
register(BobBookFactory, "book_bob")
Then any use of book_bob will actually end up using the original author fixture and end up with an author whose name is "Charles Dickens" based on the docs at the time of this writing.
It doesn't appear that there's an easy fix for register to be able to look up what model_name a given factory class was registered with so I don't have a good answer on how to fix this right now.
The text was updated successfully, but these errors were encountered:
I had a similar issue with SubFactory registering automatically.
I used a new Factory with a conflicting name DocumentFactory only as a SubFactory and later the old DocumentFactory is registered. This caused the old one to not be registered and the new one to take precedent, even though I never explicitly registered it.
Which caused all references to the old factory to break, as they were now using the new one.
It appears that when processing
SubFactory
attributes on the parent factory and generating deps for the SubFactory fixture, the introspected names do not take into account whether a given factory was registered earlier with a differentmodel_name
.This gist demonstrates a failing test where the generated SubFactory fixture is expecting to find a
b_model__name
fixture when the one available is actually namedb_model_with_some_other_name__name
.https://gist.github.com/ryancausey/904ad5b77349769d32c72d413dd79a59
I think the root cause of all the issues I'm experiencing can be boiled down to this. This generally shows up when a second factory class is created from a parent subclass. Using the documentation's
AuthorFactory
as an example:If we create a second
BookFactory
subclass that usesBobAuthorFactory
as theSubFactory
:Then any use of
book_bob
will actually end up using the originalauthor
fixture and end up with an author whose name is "Charles Dickens" based on the docs at the time of this writing.It doesn't appear that there's an easy fix for
register
to be able to look up whatmodel_name
a given factory class was registered with so I don't have a good answer on how to fix this right now.The text was updated successfully, but these errors were encountered: