property/relation error goes unchecked until query instanciation

Issue #305 resolved
Former user created an issue

Adding a relation falsly build from a table object as a property to another mapper leads to an error only much later that is not recognizably connected to the actual problem.

  • Instanciating a relation from a table instead of a mapper and adding it to another mapper doesn't fail
  • blubbs.add_property('bar', relation(bar))
  • Later trying to query an unrelated table the error shows up, but not in any way recognizably connected to the actual problem.
  • query = session.query(foos)
  • Note, the correct line for adding the property would be:
  • blubbs.add_property('bar', relation(bars))

    Traceback (most recent call last): File "test_query.py", line 91, in ? query = session.query(foos) File "build/bdist.linux-i686/egg/sqlalchemy/orm/session.py", line 182, in query File "build/bdist.linux-i686/egg/sqlalchemy/orm/query.py", line 19, in init File "build/bdist.linux-i686/egg/sqlalchemy/orm/mapper.py", line 163, in compile File "build/bdist.linux-i686/egg/sqlalchemy/orm/mapper.py", line 389, in _initialize_properties File "build/bdist.linux-i686/egg/sqlalchemy/orm/mapper.py", line 1148, in init File "build/bdist.linux-i686/egg/sqlalchemy/orm/properties.py", line 209, in do_init AttributeError: 'Table' object has no attribute '_check_compile'

    #!python from sqlalchemy import Table, Column, DynamicMetaData, Integer, Sequence, String, create_engine, mapper, ForeignKey, relation, create_session

    metadata = DynamicMetaData() engine = create_engine('oracle://florian_test:florian_test@orcl') metadata.connect(engine)

    foo = Table( 'foo', metadata, Column('id', Integer, Sequence('foo_seq'), primary_key=True), )

    bar = Table( 'bar', metadata, Column('id', Integer, Sequence('bar_seq'), primary_key=True), )

    blubb = Table( 'blubb', metadata, Column('id', Integer, Sequence('blubb_seq'), primary_key=True), Column('bar_id', Integer, ForeignKey('bar.id')), )

    try: foo.create() except: pass

    try: bar.create() except: pass

    try: blubb.create() except: pass

    class Foo(object): pass foos = mapper(Foo, foo)

    class Bar(object): pass bars = mapper(Bar, bar)

    class Blubb(object): pass blubbs = mapper(Blubb, blubb) blubbs.add_property('bar', relation(bar))

    session = create_session() query = session.query(foos)

Comments (2)

  1. Log in to comment