On Tue, Nov 4, 2014 at 3:15 PM, Jonathan Vanasco <jvana...@gmail.com> wrote:
>
> I have a "permissions check" routine that repeatedly queries for a certain
> Foo2Bar table
>
>     class Foo2Bar(Base):
>         __tablename__ = 'foo_2_bar'
>         id_foo = Column(Integer, ForeignKey("foo.id"), primary_key=True)
>         id_bar = Column(Integer, ForeignKey("bar.id"), primary_key=True)
>
>     print "Get Foo2Bar() 4x"
>     print id(s.query(Foo2Bar).get((1,2)))
>     print id(s.query(Foo2Bar).get((1,2)))
>     print id(s.query(Foo2Bar).get((1,2)))
>     print id(s.query(Foo2Bar).get((1,2)))
>
> When I do this on a test harness, it works exactly like it should.  It only
> hits the database once.
>
> When I do this in my app, it hits the database (postgres) unreliably.

...

> does anyone have a clue what could cause this behavior?

The code as shown, would likely exhibit that behavior with a weak
identity map. It would indeed be hard to predict when it happened
since weakrefs are cleared on garbage collection cycles, and those
happen at hard to predict times.

You could rule that out, by storing the result of get() in some
variable somewhere for the duration of the test/routine. That should
keep it in the identity map long enough to serve your purposes.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to