Preventing non-JSON-serializable types #590
-
Every now and then, our tests fail because polyfactory (or Faker) creates a Decimal for a value, and our tests fail because it tried to convert the Decimal to JSON. How would I tell faker to not use Decimals? Or is there a better way? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
For now, I told the factory to ignore one field and sets a hard value for another: class BundleFactory(ModelFactory[DocumentBundle]):
additional_info = {} # noqa: RUF012
queries = Ignore() |
Beta Was this translation helpful? Give feedback.
-
You can override the However, polyfactory should only create Decimal for fields annotated as Decimal. If we don't create a Decimal, wouldn't pydantic complain when creating the model instance?? |
Beta Was this translation helpful? Give feedback.
Aah I see. This is due to faker then. The relevant lines are here so if you override
list
,dict
etc. viaget_provider_map
, then you won't be getting anyDecimal
instances.