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
But during the update, this started raising an error: ValueError: The following fields do not exist in this model: gov_id_verification.
The Solution I Used
To resolve this, I ended up using a post_generation method to control whether the related factory should be created or not. Here’s the solution I used:
@factory.post_generationdefgov_id_verification(self, create, extracted, **kwargs):
# Override gov_id_verification to skip its creation in MemberFactory2ifcreateandextractedisnotFalse:
# Create a new government ID verification only if explicitly requestedGovernmentIDVerificationFactory(user=self, **(extractedor {}))
Question
Is there an easier way to handle such cases where I want to make related factories optional in a clean and straightforward manner?
I’d appreciate any suggestions or tips on simplifying this process.
The text was updated successfully, but these errors were encountered:
I recently updated my project from Django 3.2 to Django 5.0. One particular issue I encountered was related to
factory_boy
. Here’s what happened:The Problem
I had the following factory definition:
In previous versions, I could easily override
gov_id_verification
in a subclassed factory like this:But during the update, this started raising an error:
ValueError: The following fields do not exist in this model: gov_id_verification
.The Solution I Used
To resolve this, I ended up using a
post_generation
method to control whether the related factory should be created or not. Here’s the solution I used:Question
Is there an easier way to handle such cases where I want to make related factories optional in a clean and straightforward manner?
I’d appreciate any suggestions or tips on simplifying this process.
The text was updated successfully, but these errors were encountered: