-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Make context available to callable missing
#1700
Comments
Apologies for the delayed response. This is similar to #289 . I'm considering if we should add something along the lines of DRF's API for opting into context for validation and default functions: https://www.django-rest-framework.org/community/3.11-announcement/#validator-default-context . In the meantime, I like the workaround you described. |
missing
I think the context feature rework proposed in #1826 would solve this. |
closing, as this is addressed by using contextvars, i.e. #2707 |
Related: #394. I was hoping to use the
context
dictionary to drive field logic, but I was disappointed to find that when using themissing
parameter as a callable function, there is no avenue for accessing thecontext
data.I'd like to propose feeding the
context
dictionary as a parameter to themissing
callable (unfortunately this would be a breaking change).The rationale:
context
(if I am not mistaken) is to provide information to drive logic within a Field/Schema's methods.missing
callable is to support an asynchronous/callback mechanism to allow the missing value to be determined/defined after the field has been instantiated (i.e. during load/parse time).context
when calling themissing
callable.Below is a somewhat simplified example of what I would like to achieve.
In this specific case I have a custom field where I can define the
missing
callback on the Field itself, and have thecontext
be provided to it.Add it to a simple UserSchema... (note that the
missing
parameter is not specified in theUserId
instantiation)And then parse...
Obviously the
missing
callable does not need to be defined as method on the field, but I figured this implementation might turn some gears for other potential solutions.I'm a noob to marshmallow, so perhaps there are better ways to skin/think about this. Much appreciated!
And thank your for all of your work!
The text was updated successfully, but these errors were encountered: