Commits

Mike Bayer committed d2f578f

dev

Comments (0)

Files changed (2)

lib/sqlalchemy/orm/session.py

         self.autoflush = autoflush
     def connection(self, mapper_or_class, entity_name=None):
         if isinstance(mapper_or_class, type):
-            mapper_or_class = class_mapper(mapper_or_class, entity_name=entity_name)
+            mapper_or_class = _class_mapper(mapper_or_class, entity_name=entity_name)
         if self.parent is not None:
             return self.parent.connection(mapper_or_class)
         engine = self.session.get_bind(mapper_or_class)
             
     def mapper(self, class_, entity_name=None):
         """given an Class, return the primary Mapper responsible for persisting it"""
-        return class_mapper(class_, entity_name = entity_name)
+        return _class_mapper(class_, entity_name = entity_name)
     def bind_mapper(self, mapper, bindto):
         """bind the given Mapper to the given Engine or Connection.  
         
     def query(self, mapper_or_class, entity_name=None, **kwargs):
         """return a new Query object corresponding to this Session and the mapper, or the classes' primary mapper."""
         if isinstance(mapper_or_class, type):
-            return query.Query(class_mapper(mapper_or_class, entity_name=entity_name), self, **kwargs)
+            return query.Query(_class_mapper(mapper_or_class, entity_name=entity_name), self, **kwargs)
         else:
             return query.Query(mapper_or_class, self, **kwargs)
     def _sql(self):
         
         this will free all internal references to the object.  cascading will be applied according to the
         'expunge' cascade rule."""
-        for c in [object] + list(object_mapper(object).cascade_iterator('expunge', object)):
+        for c in [object] + list(_object_mapper(object).cascade_iterator('expunge', object)):
             self.uow._remove_deleted(c)
             self._unattach(c)
         
         instance.
         """
         self._save_impl(object, entity_name=entity_name)
-        object_mapper(object).cascade_callable('save-update', object, lambda c, e:self._save_or_update_impl(c, e))
+        _object_mapper(object).cascade_callable('save-update', object, lambda c, e:self._save_or_update_impl(c, e))
 
     def update(self, object, entity_name=None):
         """Bring the given detached (saved) instance into this Session.
         This operation cascades the "save_or_update" method to associated instances if the relation is mapped 
         with cascade="save-update"."""
         self._update_impl(object, entity_name=entity_name)
-        object_mapper(object).cascade_callable('save-update', object, lambda c, e:self._save_or_update_impl(c, e))
+        _object_mapper(object).cascade_callable('save-update', object, lambda c, e:self._save_or_update_impl(c, e))
 
     def save_or_update(self, object, entity_name=None):
         """save or update the given object into this Session.
         The presence of an '_instance_key' attribute on the instance determines whether to
         save() or update() the instance."""
         self._save_or_update_impl(object, entity_name=entity_name)
-        object_mapper(object).cascade_callable('save-update', object, lambda c, e:self._save_or_update_impl(c, e))
+        _object_mapper(object).cascade_callable('save-update', object, lambda c, e:self._save_or_update_impl(c, e))
     
     def _save_or_update_impl(self, object, entity_name=None):
         key = getattr(object, '_instance_key', None)
         """mark the given instance as deleted.
         
         the delete operation occurs upon flush()."""
-        for c in [object] + list(object_mapper(object).cascade_iterator('delete', object)):
+        for c in [object] + list(_object_mapper(object).cascade_iterator('delete', object)):
             self.uow.register_deleted(c)
 
     def merge(self, object, entity_name=None):
         
         note: this method is currently not completely implemented."""
         instance = None
-        for obj in [object] + list(object_mapper(object).cascade_iterator('merge', object)):
+        for obj in [object] + list(_object_mapper(object).cascade_iterator('merge', object)):
             key = getattr(obj, '_instance_key', None)
             if key is None:
-                mapper = object_mapper(object)
+                mapper = _object_mapper(object)
                 ident = mapper.identity(object)
                 for k in ident:
                     if k is None:
             if not self.identity_map.has_key(object._instance_key):
                 raise exceptions.InvalidRequestError("Instance '%s' is a detached instance or is already persistent in a different Session" % repr(object))
         else:
-            m = class_mapper(object.__class__, entity_name=kwargs.get('entity_name', None))
+            m = _class_mapper(object.__class__, entity_name=kwargs.get('entity_name', None))
             
             # this would be a nice exception to raise...however this is incompatible with a contextual 
             # session which puts all objects into the session upon construction.
         """deprecated; a synynom for merge()"""
         return self.merge(*args, **kwargs)
 
-def object_mapper(obj):
+def _object_mapper(obj):
     return sqlalchemy.orm.object_mapper(obj)
 
-def class_mapper(class_, **kwargs):
+def _class_mapper(class_, **kwargs):
     return sqlalchemy.orm.class_mapper(class_, **kwargs)
 
 # this is the AttributeManager instance used to provide attribute behavior on objects.

test/orm/session.py

         s.save(User())
         s.flush()
         c.execute("select * from users")
-    
+        u = User()
+        s.save(u)
+        s.user_name = 'some user'
+        s.flush()
+        u = User()
+        s.save(u)
+        s.user_name = 'some other user'
+        s.flush()
+
+    def test_close_two(self):
+        c = testbase.db.connect()
+        class User(object):pass
+        mapper(User, users)
+        s = create_session(bind_to=c)
+        tran = s.create_transaction()
+        s.save(User())
+        s.flush()
+        c.execute("select * from users")
+        u = User()
+        s.save(u)
+        s.user_name = 'some user'
+        s.flush()
+        u = User()
+        s.save(u)
+        s.user_name = 'some other user'
+        s.flush()
+        assert s.transaction is tran
+        tran.close()
+
 class OrphanDeletionTest(AssertMixin):
 
     def setUpAll(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.