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

Usage of json.dumps before deserialization @import #212

Open
ThibautBorn opened this issue Jul 13, 2023 · 2 comments
Open

Usage of json.dumps before deserialization @import #212

ThibautBorn opened this issue Jul 13, 2023 · 2 comments
Labels
question Further information is requested

Comments

@ThibautBorn
Copy link
Contributor

Recently there was a change to deserializing when importing a new item. Now the item data is converted to a json string before the deserializer using json.dumps. This causes issues when deserializing decimal values however. So i was wondering why this change was made and if this change could be reverted?

@ThibautBorn ThibautBorn added the question Further information is requested label Jul 13, 2023
@pbauer
Copy link
Member

pbauer commented Jul 14, 2023

The reason is that not all deserializers support the data=item format and the default seems to be to use json_body(self.request) (e.g. https://github.com/plone/plone.restapi/blob/master/src/plone/restapi/deserializer/site.py#L37).
So reverting this will break importing the site-root. I have not had to deal with decimals so far. Please tell me if you find another solution.

@avoinea
Copy link
Member

avoinea commented Jul 31, 2023

I confirm this is a breaking one:

Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/collective/exportimport/import_content.py", line 409, in import_new_content
    new = self.handle_new_object(item, index, new)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/collective/exportimport/import_content.py", line 430, in handle_new_object
    self.request["BODY"] = json.dumps(item)
                           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Decimal is not JSON serializable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants