recursion bug when filtering with .in_() on a mapped property

Issue #1221 resolved
Former user created an issue

The (attached, also partially quoted below) test case results in:

RuntimeError: maximum recursion depth exceeded

This appears to have something to do with filtering a query using .in() when what is being tested is a mapped property. I'm not sure if the ability to filter in this particular way is meant to be supported at this time or not, but it seemed worth submitting since in general SA seems to work toward making mapped properties behave as much as possible like ordinary python properties.

Thanks! - Eric

nodes = Table('nodes', metadata,
    Column('id', Integer, primary_key=True),
    Column('parent_id', Integer, ForeignKey('nodes.id'))
)
fribbits = Table('fribbits', metadata,
                 Column('id', Integer, primary_key=True),
                 Column('node_id', Integer, ForeignKey('nodes.id'))
)
class Node(object):
    def list_to_root(self):
        if self.parent_id == None:
            return [       else:
            result = [](]
)
            result.append(self)
            return result + self.parent.list_to_root()

mapper(Node, nodes, properties={
        'parent': relation(Node, uselist=False, remote_side=[nodes.c.id](nodes.c.id))
        })
mapper(Fribbit, fribbits, properties={
    'node': relation(Node, uselist=False)
    })

f = session.query(Fribbit).get(4444)
n = f.node
l = n.list_to_root()

print "*working case* here are all Fribbits whose nodes are in that ancestry:",
y = map(lambda item:item.id, l)
t = session.query(Fribbit).filter(Fribbit.node_id.in_(y)).all()
print t

print "**broken case** here are all Fribbits whose nodes are in that ancestry:",
z = session.query(Fribbit).filter(Fribbit.node.in_(l)).all()
print z

Comments (4)

  1. Former user Account Deleted

    In the docs, I see mainly examples of using in_() with lists of simple things like strings or numbers, and not much suggestion that it should be expected to work against lists of objects which happen to be mapped properties. I don't know if the problem I ran into is being caused just by using in_() against a list of objects, or if it's the fact that those objects are instances of a mapped class that has a relation to the class being queried... or what.

    But I only realized that in_() only shows up testing simple lists of values in the docs after I had tried to use it in this more complicated scenario. My point being that I intuitively tried using it this way, thus support of such use could be considered a worthy goal. Though obviously the workaround was easy, just using an object id column as a proxy for the test.

  2. Log in to comment