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

Maximum recursion level reached when circular reference #262

Closed
cscps opened this issue Apr 14, 2017 · 2 comments
Closed

Maximum recursion level reached when circular reference #262

cscps opened this issue Apr 14, 2017 · 2 comments

Comments

@cscps
Copy link

cscps commented Apr 14, 2017

import ujson
class C1:
    def __init__(self, r):
        self.r = r

class C2:
    def __init__(self):
        self.r = C1(self)

>>>print(ujson.dumps(C2()))


OverflowError: Maximum recursion level reached

Maybe there should be an arg to set the max recursion or check circular reference as built-in json library does

@cscps cscps changed the title Maximum recursion level reached when two object reference each other Maximum recursion level reached when circular reference Apr 14, 2017
@hugovk
Copy link
Member

hugovk commented Mar 7, 2020

Similar to #258, I now get a repr problem with UltraJSON 2.0.0 on macOS Mojave/Python 3.8.1:

>>> print(ujson.dumps(C2()))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: � is not JSON serializable

@hugovk
Copy link
Member

hugovk commented Mar 13, 2020

This has been fixed in UltraJSON 2.0 by 53f85b1:

Removed generic serialization of objects/iterables

The behavior of ujson has always been to try to serialize all objects in
any way possible. This has been quite a deviation from other json
libraries, including Pythons standard json module, and the source of a
lot of confusion and bugs. Removing this quirk moves ultrajson closer to
the expected behavior.

Instead of trying to coerce serialization ultrajson will now throw a
TypeError: "repr(obj) is not JSON serializable" exception.

The "�" bit is another issue: #258.

@hugovk hugovk closed this as completed Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants