]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- ForeignKey reports better error message for column not found
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Sep 2006 17:10:53 +0000 (17:10 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Sep 2006 17:10:53 +0000 (17:10 +0000)
- change in verbiage when join conditions are figured out (and fail)

lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/properties.py
lib/sqlalchemy/schema.py

index f8df559022b3a704dc21c24232a453accccf8473..1539a949cb6096b7a6702f9c4035a3fdfc66fb53 100644 (file)
@@ -566,7 +566,7 @@ class Mapper(object):
             prop.adapt_to_inherited(key, mapper)
         
     def __str__(self):
-        return "Mapper| " + str(id(self)) + "|" + self.class_.__name__ + "|" + (self.entity_name is not None and "/%s" % self.entity_name or "") + (self.local_table and self.local_table.name or str(self.local_table)) + "|is_primary=" + repr(self._is_primary_mapper())
+        return "Mapper|" + self.class_.__name__ + "|" + (self.entity_name is not None and "/%s" % self.entity_name or "") + (self.local_table and self.local_table.name or str(self.local_table)) + (not self._is_primary_mapper() and "|non-primary" or "")
     
     def _is_primary_mapper(self):
         """returns True if this mapper is the primary mapper for its class key (class + entity_name)"""
index 23398f8fef79a9c0183295fa57c65f4c50b99922..e05f641a54cc77db4bcf74514aa11fc525d03ea8 100644 (file)
@@ -238,7 +238,7 @@ class PropertyLoader(mapper.MapperProperty):
                 if self.primaryjoin is None:
                     self.primaryjoin = sql.join(self.parent.unjoined_table, self.target).onclause
         except exceptions.ArgumentError, e:
-            raise exceptions.ArgumentError("Error determining primary and/or secondary join for relationship '%s' between mappers '%s' and '%s'.  You should specify the 'primaryjoin' (and 'secondaryjoin', if there is an association table present) keyword arguments to the relation() function (or for backrefs, by specifying the backref using the backref() function with keyword arguments) to explicitly specify the join conditions.  Nested error is \"%s\"" % (self.key, self.localparent, self.mapper, str(e)))
+            raise exceptions.ArgumentError("Error determining primary and/or secondary join for relationship '%s' between mappers '%s' and '%s'.  If the underlying error cannot be corrected, you should specify the 'primaryjoin' (and 'secondaryjoin', if there is an association table present) keyword arguments to the relation() function (or for backrefs, by specifying the backref using the backref() function with keyword arguments) to explicitly specify the join conditions.  Nested error is \"%s\"" % (self.key, self.localparent, self.mapper, str(e)))
         # if the foreign key wasnt specified and theres no assocaition table, try to figure
         # out who is dependent on who. we dont need all the foreign keys represented in the join,
         # just one of them.  
index 4b6b8d6be049c490a8b54998669079351854fda9..3cbb7f9e461b970dddc613f1b7901483a0b680f5 100644 (file)
@@ -581,11 +581,14 @@ class ForeignKey(SchemaItem):
                 else:
                     (schema,tname,colname) = m.group(1,2,3)
                 table = Table(tname, parenttable.metadata, mustexist=True, schema=schema)
-                if colname is None:
-                    key = self.parent
-                    self._column = table.c[self.parent.key]
-                else:
-                    self._column = table.c[colname]
+                try:
+                    if colname is None:
+                        key = self.parent
+                        self._column = table.c[self.parent.key]
+                    else:
+                        self._column = table.c[colname]
+                except KeyError, e:
+                    raise exceptions.ArgumentError("Could not create ForeignKey '%s' on table '%s': table '%s' has no column named '%s'" % (self._colspec, parenttable.name, table.name, e.args[0]))
             else:
                 self._column = self._colspec