Hello,
I have a scenario like below :

- Session has weak_identity_map set to true. Therefore session is self
pruning.
- In some situations, the session might contain object references, which
have been deleted by other sessions from the database.
- In such cases, I want to remove the references of those deleted objects
from this session's identity_map.
- Running a gc.collect() could be expensive.
- I just have primary key of the object that got deleted from another
session.

Which is the fastest way to remove this specific object from the session's
identity_map? Currently I am doing something like below :

# dkey is a tuple and will have the primary key of the object that just got
deleted from the db through another session.

dobj = None
for obj in session.identity_map:
   c, k = obj #extract class and the primary key tuple from the object.
   if k == dkey:
     dobj = obj #get the object reference to be deleted.
     break  #The session wont contain multiple references to the same obj
anyway.

session.identity_map.remove_key(dobj)  #delete that object from the session.

I am worried about the iteration that I do, which could consume significant
time in case session has a lot of objects after a bulk query/insertion etc.,
Is there a better way to do this?

Thanks for the help!

Regards,
Harish

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to