-
Notifications
You must be signed in to change notification settings - Fork 73
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
Inject constructed arguments schema into view method #514
Comments
Hi. Before adding another feature, I'd like to see if this can be addressed with current code with a trick on your side. Do you think you could define a base Schema with a |
Hmm, an ugly hack, :) This could work in some situations, but not all (mostly as you say the objects that the schema returns that don't have My schemas sometimes return SQLAlchemy models, so it does work there but makes me nervous about potential DB column clashes. However, the biggest problem is that Marshmallow doesn't guarantee the ordering of the post_load methods. So your proposal could end up copying context before it's available. The cleanest solution would be the one I proposed, I think. |
This would indeed have to be done on webargs. Seems like a corner case, but if the change is not too impacting, it could be acceptable. Would you like to take a stab at it? |
I'll see what I can do, I'll have to re-familiarise myself with the problem since it's been over a year. |
Using this example from the documentation:
The
arguments
decorator will make sure the results of the PetQueryArgsSchema are injected into the wrapped view method, but the schema object is thrown away once finished with.It would be very useful to also optionally inject the constructed schema object as well, since I have quite a few schemas that set internal context that is required in subsequent processing.
Marshmallow schemas have a similar thing when doing their own
@post_dump
etc decorators where you can usepass_orig
to get at the original data before the schema processed it. I suggest we have apass_schema
to add an extraschema=
kwarg to the wrapped method.It's possible that this needs to happen in the webargs
use_args
function and not here, but I thought I'd gather opinions on this enhancement before attempting a fix myself.The text was updated successfully, but these errors were encountered: