Hi,

read the section Session
Attributes<http://docs.sqlalchemy.org/en/latest/orm/session.html#sqlalchemy.orm.session.Session.identity_map>.
You
might just need something like len(session.identity_map) + len(session.new)
... but there are some caveats, involving exactly what you mean by the
session "holding" an object (i.e. what you need this set for):

- That assumes you want to include objects that have been added to the
session but haven't yet been flushed to the database, so they do not yet
have an identity

- It also assumes you don't want to *exclude* objects which have been
deleted in the session but whose deletion has not yet been flushed to the
database; the session is still "holding" those objects

- The identity_map is a weak-referencing map, so it may or may not still
reference objects to which your application no longer holds a reference,
depending on garbage collection. So you may get a different set before and
after calling gc.collect().

Cheers,

Gulli

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to