]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- more accurate changelog message
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 20 Jul 2008 18:36:44 +0000 (18:36 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 20 Jul 2008 18:36:44 +0000 (18:36 +0000)
- generalized the descriptor detection to any object with a __get__ attribute

CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/inheritance/basic.py

diff --git a/CHANGES b/CHANGES
index f6bd11f66cb5c3d49053e6b09af257ad5dd0c243..b10e0a1cd8511ba5a7234b852da6fce6d6dd9dd0 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -15,12 +15,17 @@ CHANGES
     - A critical fix to dynamic relations allows the 
       "modified" history to be properly cleared after
       a flush().
-    
-    - An inheriting class can now override an attribute
-      inherited from the base class with a plain descriptor, 
-      or exclude an inherited attribute via the 
+
+    - user-defined @properties on a class are detected
+      and left in place during mapper initialization.
+      This means that a table-bound column of the same
+      name will not be mapped at all if a @property is
+      in the way (and the column is not remapped to 
+      a different name), nor will an instrumented attribute
+      from an inherited class be applied.  The same
+      rules apply for names excluded using the 
       include_properties/exclude_properties collections.
-      
+
     - Added a new SessionExtension hook called after_attach().
       This is called at the point of attachment for objects
       via add(), add_all(), delete(), and merge().
index f313a09ee716632834523142b3437afcb4863aad..7332e3104ac34c8f3795043a9430d6977a0dad69 100644 (file)
@@ -647,9 +647,8 @@ class Mapper(object):
         
         """
         # check for an existing descriptor
-        if isinstance(
-            getattr(self.class_, name, None),
-            property):
+        if getattr(self.class_, name, None) \
+            and hasattr(getattr(self.class_, name), '__get__'):
             return True
         
         if (self.include_properties is not None and
index 4600ee063d91b7551303234bef4099525c8a6c3a..da03d2f995fb2b15d1a4d73186a15a9992209af3 100644 (file)
@@ -848,6 +848,29 @@ class OverrideColKeyTest(ORMTest):
         sess.add(s1)
         sess.flush()
         assert sess.query(Sub).one().data == "im the data"
+
+    def test_custom_descriptor(self):
+        """test that descriptors prevent inheritance from propigating properties to subclasses."""
+
+        class MyDesc(object):
+            def __get__(self, instance, owner):
+                if instance is None:
+                    return self
+                return "im the data"
+            
+        class Base(object):
+            pass
+        class Sub(Base):
+            data = MyDesc()
+
+        mapper(Base, base)
+        mapper(Sub, subtable, inherits=Base)
+
+        s1 = Sub()
+        sess = create_session()
+        sess.add(s1)
+        sess.flush()
+        assert sess.query(Sub).one().data == "im the data"
         
 
 if __name__ == "__main__":