Commits

Mike Bayer  committed 923fbf5

- added 'object_session' as classlevel method to Session
- moved 'identity_key' to be a classmethod on Session
- some docstrings
- merged r3229 from 0.3 branch to unconditonally quote schemaname in PG-reflected default
- name fixes in dynamic unit test

  • Participants
  • Parent commits bee200e

Comments (0)

Files changed (6)

 - mssql
     - added support for TIME columns (simulated using DATETIME) [ticket:679]
     - index names are now quoted when dropping from reflected tables [ticket:684]
+- postgres
+    - when reflecting tables from alternate schemas, the "default" placed upon
+      the primary key, i.e. usually a sequence name, has the "schema" name
+      unconditionally quoted, so that schema names which need quoting are fine.
+      its slightly unnecessary for schema names which don't need quoting
+      but not harmful.
       
 0.3.10
 - general

File doc/build/content/session.txt

-Using the Session {@name=unitofwork}
+    Using the Session {@name=unitofwork}
 ============
 
 The [Mapper](rel:advdatamapping) is the entrypoint to the configurational API of the SQLAlchemy object relational mapper.  But the primary object one works with when using the ORM is the [Session](rel:docstrings_sqlalchemy.orm.session_Session).
 
 * How can I get the `Session` for a certain object ?
 
+    Use the `object_session()` classmethod available on `Session`:
+    
         {python}
-        from sqlalchemy.orm import object_session
-        session = object_session(someobject)
+        session = Session.object_session(someobject)
 
 * Is the session threadsafe ?
 

File lib/sqlalchemy/databases/postgres.py

                     # the default is related to a Sequence
                     sch = table.schema
                     if '.' not in match.group(2) and sch is not None:
-                        default = match.group(1) + sch + '.' + match.group(2) + match.group(3)
+                        # unconditionally quote the schema name.  this could
+                        # later be enhanced to obey quoting rules / "quote schema"
+                        default = match.group(1) + ('"%s"' % sch) + '.' + match.group(2) + match.group(3)
                 colargs.append(schema.PassiveDefault(sql.text(default)))
             table.append_column(schema.Column(name, coltype, nullable=nullable, *colargs))
 

File lib/sqlalchemy/orm/scoping.py

     def do(cls, *args,**kwargs):
         return getattr(Session, name)(*args, **kwargs)
     return classmethod(do)
-for prop in ('close_all',):
+for prop in ('close_all','object_session', 'identity_key'):
     setattr(ScopedSession, prop, clslevel(prop))
     
 class _ScopedExt(MapperExtension):

File lib/sqlalchemy/orm/session.py

         self.uow = unitofwork.UnitOfWork(weak_identity_map=self.weak_identity_map)
         self.uow.echo = echo
 
-    def mapper(self, class_, entity_name=None):
-        """Given a ``Class``, return the primary ``Mapper`` responsible for
-        persisting it."""
-
-        return _class_mapper(class_, entity_name = entity_name)
-
     def bind_mapper(self, mapper, bind, entity_name=None):
         """Bind the given `mapper` or `class` to the given ``Engine`` or ``Connection``.
 
         finally:
             _recursive.remove(mapper)
             
-    def identity_key(self, *args, **kwargs):
+    def identity_key(cls, *args, **kwargs):
         """Get an identity key.
 
         Valid call signatures:
                 % ", ".join(kwargs.keys()))
         mapper = _object_mapper(instance)
         return mapper.identity_key_from_instance(instance)
-
+    identity_key = classmethod(identity_key)
+    
+    def object_session(cls, obj):
+        """return the ``Session`` to which the given object belongs."""
+        
+        return object_session(obj)
+    object_session = classmethod(object_session)
+    
     def _save_impl(self, object, **kwargs):
         if hasattr(object, '_instance_key'):
             if not self.identity_map.has_key(object._instance_key):
         return getattr(obj, '_sa_session_id', None) == self.hash_key
 
     def __contains__(self, obj):
+        """return True if the given object is associated with this session.
+        
+        The instance may be pending or persistent within the Session for a
+        result of True.
+        """
+        
         return self._is_attached(obj) and (obj in self.uow.new or self.identity_map.has_key(obj._instance_key))
 
     def __iter__(self):
+        """return an iterator of all objects which are pending or persistent within this Session."""
+        
         return iter(list(self.uow.new) + self.uow.identity_map.values())
 
     def _get(self, key):
         return self.identity_map[key]
 
     def has_key(self, key):
+        """return True if the given identity key is present within this Session's identity map."""
+        
         return self.identity_map.has_key(key)
 
     dirty = property(lambda s:s.uow.locate_dirty(),

File test/orm/dynamic.py

             sess.flush()
         self.assert_(list(u.addresses) == [])
 
-    test_backref.__name__ = "test_%s%s" % (
-        (autoflush and "autoflush" or ""),
+    test_backref.__name__ = "test%s%s" % (
+        (autoflush and "_autoflush" or ""),
         (saveuser and "_saveuser" or "_savead"),
     )
     setattr(FlushTest, test_backref.__name__, test_backref)