eve-sqlalchemy
eve-sqlalchemy copied to clipboard
Enumerator JSON serialization broken when using enumerated classes
Title mostly speaks for itself, the JSON serializer can't handle enum.Enum types, which you (can) use in sqlalchemy.types.Enum
Example code is here
Traceback:
...
File "[VENV]\site-packages\eve\methods\get.py", line 220, in _perform_find
build_response_document(document, resource, embedded_fields)
File "[VENV]\site-packages\eve\methods\common.py", line 623, in build_response_document
document[config.ETAG] = document_etag(document, ignore_fields=ignore_fields)
File "[VENV]\site-packages\eve\utils.py", line 363, in document_etag
dumps(value_, sort_keys=True, default=json_encoder.default).encode("utf-8")
File "[VENV]\site-packages\bson\json_util.py", line 408, in dumps
return json.dumps(_json_convert(obj, json_options), *args, **kwargs)
File "[VENV]\json\__init__.py", line 238, in dumps
**kw).encode(obj)
File "[VENV]\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "[VENV]\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "[VENV]\site-packages\eve\io\base.py", line 37, in default
return json.JSONEncoder.default(self, obj)
File "[VENV]\site-packages\simplejson\encoder.py", line 273, in default
o.__class__.__name__)
TypeError: Object of type ABEnum is not JSON serializable
Might be related to #183
Setup:
- Version:
0.7.0 - OS: Windows 10
- Python Version: 3.6
Thanks for the detailed report! Do you have time to give this a shot?
Your example looks like a good starting point for an integration test in the spirit of collection_class_set.py (including POST and PATCH requests). For the fix itselt take a look at _sanitize_value in utils.py.
Thanks for the quick response, but no, currently I don't have the time, I might get around to looking into it, but don't count on it 😉