

@classmethod
def define_tables(cls, metadata):
    global Table1, Table1B, Table2, Table3, Data
    table1 = Table('table1', metadata, Column('id', Integer, primary_key=True, test_needs_autoincrement=True), Column('related_id', Integer, ForeignKey('table1.id'), nullable=True), Column('type', String(30)), Column('name', String(30)))
    table2 = Table('table2', metadata, Column('id', Integer, ForeignKey('table1.id'), primary_key=True))
    table3 = Table('table3', metadata, Column('id', Integer, ForeignKey('table1.id'), primary_key=True))
    data = Table('data', metadata, Column('id', Integer, primary_key=True, test_needs_autoincrement=True), Column('node_id', Integer, ForeignKey('table1.id')), Column('data', String(30)))
    join = table1.outerjoin(table1).outerjoin(table3).alias('pjoin')

    class Table1(object):

        def __init__(self, name, data=None):
            self.name = name
            if (data is not None):
                self.data = data

        def __repr__(self):
            return ('%s(%s, %s, %s)' % (self.__class__.__name__, self.id, repr(str(self.name)), repr(self.data)))

    class Table1B(Table1):
        pass

    class Table2(Table1):
        pass

    class Table3(Table1):
        pass

    class Data(object):

        def __init__(self, data):
            self.data = data

        def __repr__(self):
            return ('%s(%s, %s)' % (self.__class__.__name__, self.id, repr(str(self.data))))
    try:
        table1_mapper = mapper(Table1, table1, select_table=join, polymorphic_on=table1.c.type, polymorphic_identity='table1', properties={
            'nxt': relationship(Table1, backref=backref('prev', foreignkey=join.c.id, uselist=False), uselist=False, primaryjoin=(join.c.id == join.c.related_id)),
            'data': relationship(mapper(Data, data)),
        })
        configure_mappers()
        assert False
    except:
        assert True
        clear_mappers()
    table1_mapper = mapper(Table1, table1, polymorphic_on=table1.c.type, polymorphic_identity='table1', properties={
        'nxt': relationship(Table1, backref=backref('prev', remote_side=table1.c.id, uselist=False), uselist=False, primaryjoin=(table1.c.id == table1.c.related_id)),
        'data': relationship(mapper(Data, data), lazy='joined', order_by=data.c.id),
    })
    table1b_mapper = mapper(Table1B, inherits=table1_mapper, polymorphic_identity='table1b')
    table2_mapper = mapper(Table2, table2, inherits=table1_mapper, polymorphic_identity='table2')
    table3_mapper = mapper(Table3, table3, inherits=table1_mapper, polymorphic_identity='table3')
    configure_mappers()
    assert (table1_mapper.primary_key == (table1.c.id,)), table1_mapper.primary_key

dataset/ETHPy150Open zzzeek/sqlalchemy/test/orm/inheritance/test_poly_linked_list.py PolymorphicCircularTest.define_tables/VarMisuse@188/265 `table2`->`table1`