Better error message in mapper function

Issue #429 resolved
Former user created an issue

Please run the following code with SQLAlchemy 0.3.3:

from sqlalchemy import *

metadata = BoundMetaData('sqlite:///test.db')

table1 = Table("table1", metadata,
    Column("id", Integer, primary_key=True),
    Column("name", Unicode))

table2 = Table("table2", metadata,
    Column("id", Integer, primary_key=True),
    Column("id1", Integer, ForeignKey("table1.id"), nullable=False),
    Column("name", Unicode))

class T1(object):
    pass

class T2(object):
    pass

mapper(T1, table1)
mapper(T2, table2, properties=dict(
    t1=relation(T1), backref="t2"))

t = T1()

This will get this error message:

sqlalchemy.exceptions.ArgumentError: 'None' is not an instance of MapperProperty or Column

Unfortunately, this error message does not help you locating the error.

Therefore I suggest the attached patch to orm/mapper.py which will result in the following much more helpful error message:

sqlalchemy.exceptions.ArgumentError: backref='t2' is not an instance of MapperProperty or Column

Now you see immediately where the error is in the code above: The braces have been put wrongly in the second mapping, you can fix it easily:

mapper(T2, table2, properties=dict(
    t1=relation(T1, backref="t2")))

Comments (2)

  1. Log in to comment