feat: optionally pass args to provider function
Description
Right now, a provider has no context about the class or field in question. Most of the time, that's fine.
In my scenario, I am generating TypeIDs which are prefixed with a specific string tied to a particular field name (more details. This requires the context of the field and model to determine a good random ID.
This change passes in the model and field meta into the provider, if the provider function accepts the right arguments with the right names.
Closes
Can should_use_default_value be overriden at the factory level instead? If always use a default for this type then should handle this case https://github.com/litestar-org/polyfactory/blob/main/polyfactory/factories/base.py#L951-L963
@adhtruong if the default value isn't used, how is the field generated? I don't understand that part of the logic yet.
Sorry, I believe I misunderstood this use case.
Guessing this is not expressible in python type system currently? This feels like a specific use case that should be pushed to custom base factory by overriding get_field_value itself if possible
Guessing this is not expressible in python type system currently? T
Nope, it's not, since the generated value is dependent on an instance of TypeID specific to that field. You need both the class + field reference in order to pull the right generator from the model config.
This feels like a specific use case that should be pushed to custom base factory by overriding
get_field_valueitself if possible
Yeah, could definitely see this as something specific to my app, although I'm curious if others have run into a similar problem where a type provider needs context of the class in question to generate a good result.