-
-
Notifications
You must be signed in to change notification settings - Fork 97
feat: optionally pass args to provider function #674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Can |
@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 |
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.
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. |
params = inspect.signature(method).parameters | ||
return len(params) == 2 and "cls" in params and "field_meta" in params | ||
|
||
if has_provider_args(provider): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think isinstance(..., Protocol)
where `Protocol is a more robust way of doing this check. Then can pass in the field_meta only as method is already bound
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adhtruong could you give me an example / point me to more docs here? I haven't done this sort of thing with protocols before....
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