1. idank
  2. sqlalchemy


Mike Bayer  committed 47dd7de

- Fixed bug where column_prefix wasn't being checked before
not mapping an attribute that already had class-level
name present.

  • Participants
  • Parent commits 7ae4841
  • Branches default

Comments (0)

Files changed (3)


View file
       union(query1, query2), select([foo]).select_from(query), 
+    - 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

File lib/sqlalchemy/orm/mapper.py

View file
         # 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,
             if column in self._columntoproperty:
-            if self._should_exclude(column.key, local=self.local_table.c.contains_column(column)):
+            column_key = (self.column_prefix or '') + column.key
+            if self._should_exclude(column.key, column_key, local=self.local_table.c.contains_column(column)):
-            column_key = (self.column_prefix or '') + column.key
             # adjust the "key" used for this column to that
             # of the inheriting mapper
             for mapper in self.iterate_to_root():
                 col = self.polymorphic_on
                 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)
     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
         # 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
-            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

File test/orm/mapper.py

View file
         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',
         l_m = mapper(Lala, t, exclude_properties=('vendor_id', 'boss_id'),
+        hd_m = mapper(HasDef, t, column_prefix="h_")
             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',