Skip to content
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

Enumerator JSON serialization broken when using enumerated classes #185

Open
madsmtm opened this issue Oct 25, 2018 · 2 comments
Open

Enumerator JSON serialization broken when using enumerated classes #185

madsmtm opened this issue Oct 25, 2018 · 2 comments

Comments

@madsmtm
Copy link

madsmtm commented Oct 25, 2018

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
@dkellner
Copy link
Collaborator

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.

@madsmtm
Copy link
Author

madsmtm commented Oct 26, 2018

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 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants