From 2a32d9985988413712fc40ff6f6339b2ec83e381 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 16 Sep 2005 06:34:21 +0000 Subject: [PATCH] --- lib/sqlalchemy/util.py | 19 ++++++++++++++++--- test/mapper.py | 12 +++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index de252f44ce..6f2478a92f 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -149,6 +149,8 @@ class HistoryArraySet(UserList.UserList): del self.data[i] i -= 1 + def hash(self): + return id(self) def _setrecord(self, item): try: val = self.records[item] @@ -272,8 +274,8 @@ class ScopedRegistry(object): self.application = createfunc() self.threadlocal = {} self.scopes = { - 'application' : {'call' : self._call_application, 'clear' : self._clear_application}, - 'thread' : {'call' : self._call_thread, 'clear':self._clear_thread} + 'application' : {'call' : self._call_application, 'clear' : self._clear_application, 'set':self._set_application}, + 'thread' : {'call' : self._call_thread, 'clear':self._clear_thread, 'set':self._set_thread} } def __call__(self, scope = None): @@ -281,11 +283,19 @@ class ScopedRegistry(object): scope = self.defaultscope return self.scopes[scope]['call']() + def set(self, obj, scope = None): + if scope is None: + scope = self.defaultscope + return self.scopes[scope]['set'](obj) + def clear(self, scope = None): if scope is None: scope = self.defaultscope return self.scopes[scope]['clear']() - + + def _set_thread(self, obj): + self.threadlocal[thread.get_ident()] = obj + def _call_thread(self): try: return self.threadlocal[thread.get_ident()] @@ -298,6 +308,9 @@ class ScopedRegistry(object): except KeyError: pass + def _set_application(self, obj): + self.application = obj + def _call_application(self): return self.application diff --git a/test/mapper.py b/test/mapper.py index 46cc211a89..a9b5a40bff 100644 --- a/test/mapper.py +++ b/test/mapper.py @@ -317,20 +317,30 @@ class SaveTest(AssertMixin): # assert the first one retreives the same from the identity map nu = m.get(u.user_id) self.assert_(u is nu) - + + print "STEP 1" + print repr(objectstore.identity_map) + # clear out the identity map, so next get forces a SELECT objectstore.clear() + print "STEP 2" + print repr(objectstore.identity_map) + # check it again, identity should be different but ids the same nu = m.get(u.user_id) self.assert_(u is not nu and u.user_id == nu.user_id and nu.user_name == 'savetester') # change first users name and save u.user_name = 'modifiedname' + print "STEP 3" + print repr(objectstore.identity_map) objectstore.uow().commit() # select both + #objectstore.clear() userlist = m.select(users.c.user_id.in_(u.user_id, u2.user_id), order_by=[users.c.user_name]) + print repr(userlist) # making a slight assumption here about the IN clause mechanics with regards to ordering self.assert_(u.user_id == userlist[0].user_id and userlist[0].user_name == 'modifiedname') self.assert_(u2.user_id == userlist[1].user_id and userlist[1].user_name == 'savetester2') -- 2.47.2