ugh can you attach a zipfile please, they came out inline
On Nov 6, 2007, at 5:46 PM, [EMAIL PROTECTED] wrote:
sorry, here the files
hi.
i have somewhat messy setup (~test case), about association with
intermediate table/class, double pointing to one side and single
pointing to another. i do set up both A-links in one item; and set up
only first in another item, the other link (a2_link) is pre-set to
None.
And, i have the error below since r3695.
The error seems to disappear if i do not explicitly initiate the
a2_link
to None - dont touch it or set to some object.
Any idea what's wrong?
...
File /home/az/src/dbcook/sqlalchemy/orm/sync.py, line 91, in
execute
rule.execute(source, dest, obj, child, clearkeys)
File /home/az/src/dbcook/sqlalchemy/orm/sync.py, line 139, in
execute
raise exceptions.AssertionError(Dependency rule tried to blank-
out
primary key column '%s' on instance '%s' % (str(self.dest_column),
mapperutil.instance_str(dest)))
sqlalchemy.exceptions.AssertionError: Dependency rule tried to
blank-out
primary key column 'IntermediateAB.a2_link_id' on instance
'[EMAIL PROTECTED]'
from sa_gentestbase import *
setup()
Base.__repr__ = Base.__str__
#===
#PYTHONPATH=`pwd`/..:/home/az/src/hor-trunk python mapper/
relation.py -v generate
#config: db=, debug=, default_lazy=False, echo=False,
force_lazy=False, generate=True, log_sa=, lower_pu=True
#= generated SA set-up
t = Test_SA( 'setUp' )
t.setUp()
meta = t.meta
table_A = Table( 'A', meta,
Column( 'name', String, ),
Column( 'db_id', primary_key= True, type_= Integer, ),
)
table_B = Table( 'B', meta,
Column( 'name', String, ),
Column( 'db_id', primary_key= True, type_= Integer, ),
)
table_IntermediateAB = Table( 'IntermediateAB', meta,
Column( 'color', String, ),
Column( 'a_link_id', Integer, ForeignKey( 'A.db_id', ),
nullable= False, primary_key= True, ),
Column( 'a2_link_id', Integer, ForeignKey( 'A.db_id', ),
nullable= True, primary_key= True, ),
Column( 'b_boza_id', Integer, ForeignKey( 'B.db_id', ),
nullable= False, primary_key= True, ),
)
meta.create_all()
class A( Base):
props = ['db_id', 'name']
class B( Base):
props = ['db_id', 'name']
class IntermediateAB( Base):
props = ['db_id', 'color', 'a_link', 'a2_link', 'b_boza']
mapper_A = mapper( A, table_A,)
mapper_A.add_property( 'all_ab', relation( IntermediateAB,
#collection_class= bound method type._CollectionFactory
of class '__main__.IntermediateAB',
lazy= True,
primaryjoin= table_IntermediateAB.c.a_link_id ==
table_A.c.db_id,
remote_side= table_IntermediateAB.c.a_link_id,
uselist= True,
) )
mapper_B = mapper( B, table_B,)
mapper_IntermediateAB = mapper( IntermediateAB,
table_IntermediateAB, allow_null_pks=True)
mapper_IntermediateAB.add_property( 'a_link', relation( A,
foreign_keys= table_IntermediateAB.c.a_link_id,
lazy= False,
primaryjoin= table_IntermediateAB.c.a_link_id ==
table_A.c.db_id,
remote_side= table_A.c.db_id,
uselist= False,
) )
mapper_IntermediateAB.add_property( 'a2_link', relation( A,
foreign_keys= table_IntermediateAB.c.a2_link_id,
lazy= False,
primaryjoin= table_IntermediateAB.c.a2_link_id ==
table_A.c.db_id,
remote_side= table_A.c.db_id,
uselist= False,
) )
mapper_IntermediateAB.add_property( 'b_boza', relation( B,
foreign_keys= table_IntermediateAB.c.b_boza_id,
lazy= False,
primaryjoin= table_IntermediateAB.c.b_boza_id ==
table_B.c.db_id,
remote_side= table_B.c.db_id,
uselist= False,
) )
#
a = A( name= 'a1')
a3 = A( name= 'a3')
b1 = B( name= 'b1' )
b2 = B( name= 'b2' )
a.all_ab.append( IntermediateAB( b_boza= b1, color='green', a2_link
= a3) )
a.all_ab.append( IntermediateAB( b_boza= b2, color='',
a2_link = a3 #XXX
) )
print '', [i.b_boza for i in a.all_ab]
s= create_session()
for z in locals().values():
if isinstance( z, Base): s.save(z)
s.flush()
s.clear()
for t in table_B, table_A, table_IntermediateAB:
print t,':', str( list( t.select().execute() ))
s= create_session()
aa = s.query( A ).filter_by(name='a1').first()
print aa
print 'xxx'
l = [i.b_boza for i in aa.all_ab]
print '', l
assert len(l) ==2
#expected output:
# [B/id=None( name=b1 ), B/id=None( name=b2 )]
#=== whole database:
#class '__main__.B' : [(u'b1', 1), (u'b2', 2)]
#class '__main__.A' : [(None, u'a3', 1), (None, u'a1', 2)]
#class '__main__.IntermediateAB' : [(None, u'green', 2, 1, 1),
(None, u'', 2, None, 2)]
#A/id=2( name=a1 )
#xxx
# [B/id=1( name=b1 ), B/id=2( name=b2 )]
#$Id: