-
-
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
Support for read-only fields #61
Comments
You could do something like: from marshmallow import fields, Schema, ValidationError
def read_only(val):
if val is not fields.missing:
raise ValidationError('Cannot pass a read-only field.')
class AlbumSchema(Schema):
published = fields.Date(validate=read_only)
title = fields.Str()
s = AlbumSchema()
result = s.load({'published': '2014-11-18'})
print(result.errors) # {'published': ['Cannot pass a read-only field.']} |
This works, but what do you think about making |
I looked for a read only attribute as well. |
I will consider adding a read-only flag as a kwarg. Thank you for your input. |
+1 |
I am leaning towards adding this feature, but I will probably call the parameter Thoughts? |
Added in #131 |
It would be nice to have the ability to mark fields as read-only. When deserializing, validation should fail if field(s) marked as read-only are present in the target dictionary.
The text was updated successfully, but these errors were encountered: