booby icon indicating copy to clipboard operation
booby copied to clipboard

__repr__() causes maximum recursion depth error

Open SteveGZr opened this issue 9 years ago • 4 comments

The repr() function of self-referencing Models and Models referencing to other Models which reference to the first one, cause an "maximum recursion depth" error. Because the repr() function is called for every referenced model over and over again. For example if you have something like this:

class Address(Model):
    street = String()
    persons = Collection(Person)

 class Person(Model):
     name = String()
     addresses = Collection(Address)

And repr() is called on an instance of one of the models, it causes the "maximum recursion depth" error.

SteveGZr avatar Oct 30 '15 13:10 SteveGZr

Same happens if I try to use the class as a static field of itself:

class Division(Model):
   name = String()
   id = Integer

Division.parent = Division()

makkus avatar Nov 17 '15 00:11 makkus

Personally, I would remove the __repr__() functions and use the built-in instead, in most cases you do not need this output when __repr__() is called.

SteveGZr avatar Nov 18 '15 07:11 SteveGZr

Is there a chance that you are going to merge the corresponding pull request? I still haven't found a good reason for keeping those custom __repr__() functions..

SteveGZr avatar Aug 22 '16 12:08 SteveGZr

Bump

SteveGZr avatar Oct 08 '19 09:10 SteveGZr