Hi, I've analyzed my previous problem and boiled it down to a test program
(atached).
There's two issues connected to it both visible in the test programm as
appended tracebacks.

To the basic principle. I have three tables, one base table, one table that in
herits base and antother table that inherits the one that inherits from base.
Expressed in more simple terms, I've got A, B inheriting A, C inheriting B.

On why I do such wicked things: Say I've got something like content. So there's
page content. But there can be different kinds of pages, like a Link list, a
news teaser etc. So page would inherit content, and news teaser would inherit
page. On the other hand there can be products, which also inherit content. So
there you are.

Cheers,
Florian
engine = create_engine('oracle://dsn=orcl&user=test&password=test')

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

bar = Table('bar', engine,
    Column('id', Integer, ForeignKey('foo.id'), primary_key=True))

blub = Table('blub', engine,
    Column('id', Integer, ForeignKey('bar.id'), primary_key=True))

blub_bar = Table('bar_blub', engine,
    Column('blub_id', Integer, ForeignKey('blub.id')),
    Column('bar_id', Integer, ForeignKey('bar.id')))

blub_foo = Table('blub_foo', engine,
    Column('blub_id', Integer, ForeignKey('blub.id')),
    Column('foo_id', Integer, ForeignKey('foo.id')))

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

class Bar(object): pass
Bar.mapper = mapper(Bar, bar, inherits=Foo.mapper)

class Blub(object): pass
Blub.mapper = mapper(Blub, blub, inherits=Bar.mapper)
#Blub.mapper.add_property('bars', relation(Bar.mapper, blub_bar, lazy=False)) #traceback 1
Blub.mapper.add_property('foos', relation(Foo.mapper, blub_foo, lazy=False))

tables = [foo, bar, blub, blub_bar, blub_foo]

for table in reversed(tables):
    try: table.drop()
    except: pass

for table in tables:
    try: table.create()
    except: pass

foo.insert().execute()
foo.insert().execute()
bar.insert().execute(id=1)
bar.insert().execute(id=2)
blub.insert().execute(id=1)
blub_bar.insert().execute(blub_id=1, bar_id=2)
blub_foo.insert().execute(blub_id=1, foo_id=2)

Blub.mapper.get_by(id=1) #traceback 2

## traceback 1 ##
'''
Traceback (most recent call last):
  File "testalchemy.py", line 92, in ?
    Blub.mapper.add_property('bars', relation(Bar.mapper, blub_bar, lazy=False)) #traceback 1
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/mapping/mapper.py", line 198, in add_property
    prop.init(key, self)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/mapping/mapper.py", line 822, in init
    self.do_init(key, parent)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/mapping/properties.py", line 213, in do_init
    self.do_init_subclass(key, parent)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/mapping/properties.py", line 650, in do_init_subclass
    self.eagertarget = self.target.alias()
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/sql.py", line 564, in alias
    return Alias(self, name)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/sql.py", line 918, in __init__
    n = getattr(self.original, 'name')
AttributeError: 'Join' object has no attribute 'name'
'''

## traceback 2 ##
'''
Traceback (most recent call last):
  File "testalchemy.py", line 113, in ?
    for f in Blub.mapper.get_by(id=1): #traceback 2
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/mapping/mapper.py", line 357, in get_by
    x = self.select_whereclause(self._by_clause(*args, **params), limit=1)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/mapping/mapper.py", line 459, in select_whereclause
    return self._select_statement(statement, params=params)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/mapping/mapper.py", line 479, in _select_statement
    return self.instances(statement.execute(**params), **kwargs)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/sql.py", line 407, in execute
    return c.execute(*multiparams, **params)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/sql.py", line 302, in execute
    return self.engine.execute_compiled(self, params)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/engine.py", line 583, in execute_compiled
    proxy(str(compiled), parameters)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/engine.py", line 578, in proxy
    self.execute(statement, parameters, connection=connection, cursor=cursor, return_raw=True)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/engine.py", line 629, in execute
    self._execute(cursor, statement, parameters)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.3-py2.4.egg/sqlalchemy/engine.py", line 649, in _execute
    raise exceptions.SQLError(statement, parameters, e)
sqlalchemy.exceptions.SQLError: (DatabaseError) ORA-00904: "FOO_34D0"."ID": invalid identifier
'''

Reply via email to