Misleading error message

Issue #2888 resolved
smurf created an issue

Consider the following tables:

class Unit(Base):
    __tablename__ = 'unit'

    id = Column(Integer, primary_key=True)
    name = Column(String(20))

    def __repr__(self):
        return "<%s:%s:%s>" % (self.__class__.__name__,self.id,self.name)


class HourData(Base):
    __tablename__ = 'hourdata'
    id = Column(Integer, primary_key=True)

    datum = Column(Date, nullable=False)
    hour = Column(Integer, nullable=False)

    unit_id = Column(Integer, ForeignKey('unit.id', name="fk_hd_unit", use_alter=True), nullable=False)
    unit = relationship("unit", backref='hours')

Executing this statement

session.query(Unit)

Then results in this error message:

sqlalchemy.exc.ArgumentError: Class object expected, got 'Table('unit', MetaData(bind=None), Column('id', Integer(), table=<unit>, primary_key=True, nullable=False), Column('name', String(length=20), table=<unit>), Column('mieter_id', Integer(), ForeignKey('mieter.id'), table=<unit>, nullable=False), schema=None)'.

This is totally misleading, because the actual error is in table HourData – whose relationship statement is supposed to refer to "Unit" instead of "unit". An error like this is impossible to figure out unless you happen to find the explanation in stackoverflow.

http://stackoverflow.com/questions/8170333/sqlalchemy-expects-an-object-but-finds-a-table#answer-9558936

Thus, please fix this error message. It should at least tell me which relationship statement in which table is actually broken.

Comments (2)

  1. Log in to comment