]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where column_prefix wasn't being checked before
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Mar 2009 21:45:57 +0000 (21:45 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Mar 2009 21:45:57 +0000 (21:45 +0000)
      not mapping an attribute that already had class-level
      name present.

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

diff --git a/CHANGES b/CHANGES
index 14a9c16ab6d2974a998deb38b9d120fc36a75593..35af1e41b1ea25798b4785ad9675bb2408b2d7c0 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -19,6 +19,10 @@ CHANGES
       union(query1, query2), select([foo]).select_from(query), 
       etc.
 
+    - Fixed bug where column_prefix wasn't being checked before
+      not mapping an attribute that already had class-level 
+      name present.
+
     - a session.expire() on a particular collection attribute
       will clear any pending backref additions as well, so that
       the next access correctly returns only what was present
index 98a027448eb9a5c2c560e616d956266ac1c8f373..08054072682cef648cc77e680fdf0f0bdd118e3a 100644 (file)
@@ -478,7 +478,7 @@ class Mapper(object):
         # pull properties from the inherited mapper if any.
         if self.inherits:
             for key, prop in self.inherits._props.iteritems():
-                if key not in self._props and not self._should_exclude(key, local=False):
+                if key not in self._props and not self._should_exclude(key, key, local=False):
                     self._adapt_inherited_property(key, prop, False)
 
         # create properties for each column in the mapped table,
@@ -487,11 +487,11 @@ class Mapper(object):
             if column in self._columntoproperty:
                 continue
 
-            if self._should_exclude(column.key, local=self.local_table.c.contains_column(column)):
-                continue
-
             column_key = (self.column_prefix or '') + column.key
 
+            if self._should_exclude(column.key, column_key, local=self.local_table.c.contains_column(column)):
+                continue
+
             # adjust the "key" used for this column to that
             # of the inheriting mapper
             for mapper in self.iterate_to_root():
@@ -509,7 +509,7 @@ class Mapper(object):
                 col = self.polymorphic_on
             else:
                 dont_instrument = False
-            if self._should_exclude(col.key, local=False):
+            if self._should_exclude(col.key, col.key, local=False):
                 raise sa_exc.InvalidRequestError("Cannot exclude or override the discriminator column %r" % col.key)
             self._configure_property(col.key, ColumnProperty(col, _no_instrument=dont_instrument), init=False, setparent=True)
 
@@ -937,7 +937,7 @@ class Mapper(object):
     def _is_userland_descriptor(self, obj):
         return not isinstance(obj, (MapperProperty, attributes.InstrumentedAttribute)) and hasattr(obj, '__get__')
 
-    def _should_exclude(self, name, local):
+    def _should_exclude(self, name, assigned_name, local):
         """determine whether a particular property should be implicitly present on the class.
 
         This occurs when properties are propagated from an inherited class, or are
@@ -948,12 +948,12 @@ class Mapper(object):
         # check for descriptors, either local or from
         # an inherited class
         if local:
-            if self.class_.__dict__.get(name, None)\
-                and self._is_userland_descriptor(self.class_.__dict__[name]):
+            if self.class_.__dict__.get(assigned_name, None)\
+                and self._is_userland_descriptor(self.class_.__dict__[assigned_name]):
                 return True
         else:
-            if getattr(self.class_, name, None)\
-                and self._is_userland_descriptor(getattr(self.class_, name)):
+            if getattr(self.class_, assigned_name, None)\
+                and self._is_userland_descriptor(getattr(self.class_, assigned_name)):
                 return True
 
         if (self.include_properties is not None and
index 59ae025cb30a044dc433ea96ce2af857adb0f249..d2687fa5a02691ba2c0595f5ad0747f3d373b343 100644 (file)
@@ -443,6 +443,10 @@ class MapperTest(_fixtures.FixtureTest):
         class Hoho(object): pass
         class Lala(object): pass
 
+        class HasDef(object):
+            def name(self):
+                pass
+            
         p_m = mapper(Person, t, polymorphic_on=t.c.type,
                      include_properties=('id', 'type', 'name'))
         e_m = mapper(Employee, inherits=p_m, polymorphic_identity='employee',
@@ -460,6 +464,8 @@ class MapperTest(_fixtures.FixtureTest):
         l_m = mapper(Lala, t, exclude_properties=('vendor_id', 'boss_id'),
                      column_prefix="p_")
 
+        hd_m = mapper(HasDef, t, column_prefix="h_")
+        
         p_m.compile()
         #sa.orm.compile_mappers()
 
@@ -472,7 +478,8 @@ class MapperTest(_fixtures.FixtureTest):
             have = set([p.key for p in class_mapper(cls).iterate_properties])
             want = set(want)
             eq_(have, want)
-            
+        
+        assert_props(HasDef, ['h_boss_id', 'h_employee_number', 'h_id', 'name', 'h_name', 'h_vendor_id', 'h_type'])    
         assert_props(Person, ['id', 'name', 'type'])
         assert_instrumented(Person, ['id', 'name', 'type'])
         assert_props(Employee, ['boss', 'boss_id', 'employee_number',