[orm-devel] Re: __repr__ issue?

Diedrich Vorberg diedrich@tux4web.de
Fri, 22 Nov 2002 02:30:14 +0100


>Diedrich, I think there may be an issue with __repr__ for
>selectresult objects

Yes indeed there is! The problem never showed up with the simple
doc/example/test programs. Here's the new __repr__ function:

import relationships 

    def __repr__(self):
        """
        Return a human readable (more or less) representation of this
        dbObject.
        """
        ret = []

        ret.append("pyid=" + str(id(self)))
        
        if self.oid():
            ret.append("oid=%i" % self.oid())
        else:
            ret.append("oid=NULL")
        for a in self.columns.keys():
            b = a + "="
            if self._data.has_key(a):
                val = self._data[a]
                if not isinstance(val, relationships.relationshipColumn):
                    b += repr(val.get())
                else:
                    b += repr(val.__class__)
            else:
                b += "NULL"
            ret.append(b)
            
        return "<" + self.__class__.__name__ + " (" + join(ret, " ") + ">"

The problem only occurs with models in which two classes refer to one 
another with a one2many in one and with a one2one in the other 
direction. In that case the __repr__ function tries to find out the 
content of the childclass and this causes an endless loop of course!

The new version of the function checks if the columns is a 
relationship and only prints what kind of relationship we're dealing 
with, no content. I believe actually checking for this kind of 
situation would be a little much to ask.

Thank you Mike, for pointing that out!

Diedrich

-- 
           _..._                            Diedrich Vorberg
         .'     '.
        /  _   _  \                         http://www.tux4web.de
        | (o)_(o) |                         info@tux4web.de
         \(     ) /            .---.
         //'._.'\ \           /     \       Internet Dienstleistungen
        //   .   \ \          \.@-@./       und 'Consulting'.
       ||   .     \ \         /`\_/`\
       |\   :     / |        //  _  \\      Linux Rules!
       \ `) '   (`  /_      | \     )|_
     _)``".____,.'"` (_    /`\_`>  <_/ \
     )     )'--'(     (    \__/'---'\__/
      '---`      `---`