From fcbd4f153980384089ce8d519607a1db8e7e8838 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 25 Mar 2006 00:17:51 +0000 Subject: added expunge() method to objectstore correction in attributes reset_history to really reset in all cases added unit tests testing refresh()/expire() bug that was fixed by reset_history thing --- lib/sqlalchemy/mapping/objectstore.py | 9 ++++++++- lib/sqlalchemy/mapping/unitofwork.py | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/mapping') diff --git a/lib/sqlalchemy/mapping/objectstore.py b/lib/sqlalchemy/mapping/objectstore.py index f978d16f7..6b3d7f034 100644 --- a/lib/sqlalchemy/mapping/objectstore.py +++ b/lib/sqlalchemy/mapping/objectstore.py @@ -166,6 +166,10 @@ class Session(object): for o in obj: global_attributes.trigger_history(o, lambda: refresh(o)) + def expunge(self, *obj): + for o in obj: + self.uow.expunge(obj) + def register_clean(self, obj): self._bind_to(obj) self.uow.register_clean(obj) @@ -252,7 +256,10 @@ def expire(*obj): """invalidates the data in the given objects and sets them to refresh themselves the next time they are requested.""" get_session().expire(*obj) - + +def expunge(*obj): + get_session().expunge(*obj) + def delete(*obj): """registers the given objects as to be deleted upon the next commit""" s = get_session().delete(*obj) diff --git a/lib/sqlalchemy/mapping/unitofwork.py b/lib/sqlalchemy/mapping/unitofwork.py index 2dc524897..1e5388933 100644 --- a/lib/sqlalchemy/mapping/unitofwork.py +++ b/lib/sqlalchemy/mapping/unitofwork.py @@ -104,6 +104,11 @@ class UnitOfWork(object): """returns True if the given key is present in this UnitOfWork's identity map.""" return self.identity_map.has_key(key) + def expunge(self, obj): + """removes this object completely from the UnitOfWork, including the identity map, + and the "new", "dirty" and "deleted" lists.""" + self._remove_deleted(obj) + def _remove_deleted(self, obj): if hasattr(obj, "_instance_key"): del self.identity_map[obj._instance_key] @@ -119,7 +124,7 @@ class UnitOfWork(object): del self.new[obj] except KeyError: pass - self.attributes.commit(obj) + #self.attributes.commit(obj) self.attributes.remove(obj) def _validate_obj(self, obj): -- cgit v1.2.1