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
Fail to dump JSON SCHEMA when there is a custom field inside the scheme.
To reproduce:
class PinCode(fields.Field):
"""Field that serializes to a string of numbers and deserializes
to a list of numbers.
"""
def _serialize(self, value, attr, obj, **kwargs):
if value is None:
return ""
return "".join(str(d) for d in value)
def _deserialize(self, value, attr, data, **kwargs):
return [int(c) for c in value]
class UserSchema(Schema):
name = fields.String()
email = fields.String()
pin_code = PinCode()
bowie = dict(name="David Bowie", email="[email protected]", pin_code="1234")
schema = UserSchema()
pprint(schema.fields)
data = schema.dump(bowie)
result = schema.load(data)
print(JSONSchema().dump(schema)) # <- Error occurs here.
Error message:
return self._serialize(value, attr, obj, **kwargs)
File "/Users/kevin/opt/anaconda3/envs/flyte/lib/python3.8/site-packages/marshmallow/fields.py", line 1864, in _serialize
return self._serialize_method(obj)
File "/Users/kevin/opt/anaconda3/envs/flyte/lib/python3.8/site-packages/marshmallow_jsonschema/base.py", line 163, in get_properties
schema = self._get_schema_for_field(obj, field)
File "/Users/kevin/opt/anaconda3/envs/flyte/lib/python3.8/site-packages/marshmallow_jsonschema/base.py", line 266, in _get_schema_for_field
pytype = self._get_python_type(field)
File "/Users/kevin/opt/anaconda3/envs/flyte/lib/python3.8/site-packages/marshmallow_jsonschema/base.py", line 251, in _get_python_type
raise UnsupportedValueError("unsupported field type %s" % field)
marshmallow_jsonschema.exceptions.UnsupportedValueError: unsupported field type <fields.PinCode(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=False, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.'})>
The text was updated successfully, but these errors were encountered:
Fail to dump JSON SCHEMA when there is a custom field inside the scheme.
To reproduce:
Error message:
The text was updated successfully, but these errors were encountered: