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
Update required field status #192
Comments
@morgan If you're using a framework with a thread-local request object, you could do something like: from flask import request
from marshmallow import missing, Schema, fields, ValidationError
def required_on_post(val):
if request.method == 'POST':
if val is missing:
raise ValidationError('Field is required')
class UserSchema(Schema):
password = fields.Str(validate=required_on_post, load_only=True) Of course, this can be generalized with a validator class like |
Also see #272 for a similar question and solution. Closing this for now. |
Hey @sloria ! Grateful Marshmallow user here--just wanted to update this issue as I recently came across it in Google search results. This particular solution will not work in To the other forsaken souls finding this issue: use |
Pretty normal operation, feel like I am possibly missing something. Have a schema for creation where fields are required in order to create the object. Then during edit (such as a PATCH operation), certain fields are no longer required. Such as updating a user that required a password at creation but doesn't require the password field for an update.
Currently, I'm doing something like this to solve the problem:
Feel there should be a more elegant way to modify the field itself. What are your recommendations for handling this?
The text was updated successfully, but these errors were encountered: