Mike Bayer avatar Mike Bayer committed b65cbfb

when raising about columns not present, include the name of the property it's trying to configure,
to eliminate confusion over attributes not properly placed inside of a relationship().

Comments (0)

Files changed (3)

lib/sqlalchemy/orm/mapper.py

                             self.mapped_table._reset_exported()
                         mc = self.mapped_table.corresponding_column(c)
                         if mc is None:
-                            raise sa_exc.ArgumentError("Column '%s' is not represented in mapper's table.  "
+                            raise sa_exc.ArgumentError("When configuring property '%s' on %s, "
+                                "column '%s' is not represented in the mapper's table.  "
                                 "Use the `column_property()` function to force this column "
-                                "to be mapped as a read-only attribute." % c)
+                                "to be mapped as a read-only attribute." % (key, self, c))
                     mapped_column.append(mc)
                 prop = ColumnProperty(*mapped_column)
             else:
-                raise sa_exc.ArgumentError("WARNING: column '%s' conflicts with property '%r'.  "
+                raise sa_exc.ArgumentError("WARNING: when configuring property '%s' on %s, column '%s' "
+                    "conflicts with property '%r'.  "
                     "To resolve this, map the column to the class under a different "
                     "name in the 'properties' dictionary.  Or, to remove all awareness "
                     "of the column entirely (including its availability as a foreign key), "
                     "use the 'include_properties' or 'exclude_properties' mapper arguments "
-                    "to control specifically which table columns get mapped." % (column.key, prop))
+                    "to control specifically which table columns get mapped." % 
+                    (key, self, column.key, prop))
 
         if isinstance(prop, ColumnProperty):
             col = self.mapped_table.corresponding_column(prop.columns[0])

test/orm/test_mapper.py

 
     @testing.resolve_artifact_names
     def test_column_not_present(self):
-        assert_raises_message(sa.exc.ArgumentError, "not represented in mapper's table", mapper, User, users, properties={
+        assert_raises_message(sa.exc.ArgumentError, "not represented in the mapper's table", mapper, User, users, properties={
             'foo':addresses.c.user_id
         })
         

test/orm/test_query.py

 
     def test_external_columns_bad(self):
 
-        assert_raises_message(sa_exc.ArgumentError, "not represented in mapper's table", mapper, User, users, properties={
+        assert_raises_message(sa_exc.ArgumentError, "not represented in the mapper's table", mapper, User, users, properties={
             'concat': (users.c.id * 2),
         })
         clear_mappers()
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.