thx for your reply.
Sometimes i got obsolete objects: (Pdb) id( llm_mapper.local_table.foreign_keys[0].column ) 447124816 <-obsolete column object, but semantically ok (Pdb) id( mapper.local_table.c['asl_id'] ) 448983376 <-valid column object (Pdb) id( llm_mapper.local_table.foreign_keys[0].column.metadata ) 416409552 (Pdb) id( mapper.local_table.c['asl_id'].metadata ) 416409552 My application calls Table() several times for some tables, because I don't have a static db-catalog. After a db-catalog change Table(..autoload,use_existing) is called, but foreign_keys uses old column objects (i think so). A little example: -table A references B -B is changed, Table( B, ...) is called -metadata containes the new B object -but A.foreign_keys has obsolete column objects -contains_column fails, because it compares object ids(?) Could it be? On 12 Jan., 23:54, Michael Bayer <[email protected]> wrote: > no bug in contains_column: > > from sqlalchemy import * > > m = MetaData() > > table = Table('t2', m, > Column('asl_id', Integer, > ForeignKey('public.asl_list_view.asl_id')), > schema='public' > ) > > asl_list_view = Table('asl_list_view', m, > Column('asl_id', Integer), schema='public' > ) > > print table.foreign_keys > print table.foreign_keys[0].column > print table.foreign_keys[0].column.table.schema > > print asl_list_view.c['asl_id'] > print asl_list_view.c['asl_id'].table.schema > print asl_list_view.c.contains_column(table.foreign_keys[0].column) > print table.join(asl_list_view) > > On Jan 12, 2009, at 5:45 PM, [email protected] wrote: > > > > > > > mapper.add_property( 'zzz', relation( llm_mapper, ... ) ) fails with: > > ArgumentError: Could not determine join condition between parent/ > > child tables on relation .... > > Specify a 'primaryjoin' expression. If this is a many-to-many > > relation, 'secondaryjoin' is needed as well. > > > but the foreign key exists: > > (Pdb) llm_mapper.local_table.foreign_keys > > OrderedSet([ForeignKey('public.asl_list_view.asl_id')]) > > (Pdb) llm_mapper.local_table.foreign_keys[0].column > > Column('asl_id', Integer(), table=<asl_list_view>, primary_key=True, > > nullable=False) > > (Pdb) llm_mapper.local_table.foreign_keys[0].column.table.schema > > 'public' > > (Pdb) mapper.local_table.c['asl_id'] > > Column('asl_id', Integer(), table=<asl_list_view>, primary_key=True, > > nullable=False) > > (Pdb) mapper.local_table.c['asl_id'].table.schema > > 'public' > > > the problem seems to be in the containes_column Method: > > (Pdb) mapper.local_table.c.contains_column > > ( llm_mapper.local_table.foreign_keys[0].column ) > > False > > > A litte workarround solves the problem (expression.py): > > def contains_column(self, col): > > # have to use a Set here, because it will compare the identity > > # of the column, not just using "==" for comparison which will > > always return a > > # "True" value (i.e. a BinaryClause...) > > # orig { > > #return col in util.column_set(self) > > # } > > # workarround { > > col_name = "%s" % col > > for _c in util.column_set(self): > > if col_name == "%s" % _c: > > return True > > return False > > # } > > > test: > > (Pdb) mapper.local_table.c.contains_column > > ( llm_mapper.local_table.foreign_keys[0].column ) > > True > > > ...and the property is successfully added > > > I hope it helps. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
