You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is inconsistent field_name meaning when validating fields: raising ValidationError: it expected data_key as field_name @marshmallow.validates: it expects field name
And the same issue for:
raiseValidationError(
{
"field_a": ["field_a must be greater than field_b"],
"field_b": ["field_a must be greater than field_b"],
}
)
Given the following code:
importmarshmallowfrommarshmallowimportfieldsclassApiKeySchema(marshmallow.Schema):
ip_addresses=fields.String(required=True, load_from='ipAddresses', data_key='ipAddresses')
@marshmallow.validates_schema(skip_on_field_errors=False)defvalidate_restricted_permission2(self, data, **kwargs) ->None:
raisemarshmallow.ValidationError({'ip_addresses': 'Some random error 2.'})
@marshmallow.validates_schema(skip_on_field_errors=False)defvalidate_restricted_permission(self, data, **kwargs) ->None:
ifmarshmallow.__version__.startswith('2.'):
raisemarshmallow.ValidationError('Some random error.', field_names=['ip_addresses'])
else:
raisemarshmallow.ValidationError('Some random error.', field_name='ip_addresses')
@marshmallow.validates(field_name='ip_addresses')defvalidate_ip_addresses(self, data) ->None:
raisemarshmallow.ValidationError('Some random field error.')
if__name__=='__main__':
print(marshmallow.__version__)
schema=ApiKeySchema(strict=True) ifmarshmallow.__version__.startswith('2.') elseApiKeySchema()
try:
schema.load({'ipAddresses': 'bla'})
exceptmarshmallow.ValidationErrorase:
print(e.messages)
2.15.3
{'ip_addresses': ['Some random field error.', 'Some random error.'], '_schema': [{'ip_addresses': 'Some random error 2.'}]}
2.21.0
{'ipAddresses': ['Some random field error.'], 'ip_addresses': ['Some random error.', 'Some random error 2.']}
3.20.1
{'ipAddresses': ['Some random field error.'], 'ip_addresses': ['Some random error.', 'Some random error 2.']}
how it should be:
{'ipAddresses': ['Some random field error.', 'Some random error.', 'Some random error 2.']}
Changing both field_name to data_key values then it complains about non existing field on line: @marshmallow.validates(field_name='ipAddresses')
The text was updated successfully, but these errors were encountered:
There is inconsistent field_name meaning when validating fields:
raising ValidationError: it expected data_key as field_name
@marshmallow.validates: it expects field name
And the same issue for:
Given the following code:
Changing both field_name to data_key values then it complains about non existing field on line: @marshmallow.validates(field_name='ipAddresses')
The text was updated successfully, but these errors were encountered: