and for this problem, youre looking at the reason this thing isnt
released yet! it does a lot, therefore needs a lot of abuse to find
these things. particularly the self-referential dependency code,
which only gets used with self-referential relationships, has the
downside that whenever something breaks with it, it takes me like an
hour just to wrap my head around it again. still working....
On Jan 19, 2006, at 8:13 PM, [EMAIL PROTECTED] wrote:
hi again,
i'm having some problems doing a .commit().
the test code is a very minor tweak on
the one from the previous backref thread,
and is included below.
the exception that i get is 'KeyError' -
i poked around via pdb, and see that there
are some odd things with the UOW dependencies,
but i got lost tracing where the dependencies
come from. the pdb session was (with some
cleaning):
---
KeyError: 't1'
sqlalchemy/attributes.py in get_history()
331 except KeyError, e:
--> 332 return self.class_managed(obj.__class__)[key]
(obj, **kwargs).gethistory(passive=passive, **kwargs)
333
ipdb> self
<sqlalchemy.mapping.objectstore.UOWAttributeManager object at
0x40752c8c>
ipdb> obj
<satest.C1 object at 0x407877ac>
ipdb> key
't1'
ipdb> up
sqlalchemy/mapping/properties.py in get_object_dependencies()
409 def get_object_dependencies(self, obj, uowcommit,
passive = True):
--> 410 return uowcommit.uow.attributes.get_history(obj,
self.key, passive = passive)
411
ipdb> up
sqlalchemy/mapping/objectstore.py in get_object_dependencies()
482 def get_object_dependencies(self, obj, trans, passive):
--> 483 return self.processor.get_object_dependencies(obj,
trans, passive=passive)
484
ipdb> up
sqlalchemy/mapping/objectstore.py in _sort_circular_dependencies()
617 continue
--> 618 childlist = dep.get_object_dependencies
(obj, trans, passive = True)
619 #print "GETING LIST OFF PROC",
processor.key, "OBJ", repr(obj)
ipdb> [d.processor.key for d in self.dependencies]
['t1', 't2s', 't2s', 'selfref']
ipdb>
---
i'm not entirely sure what the relation
between mapped attributes and dependencies
are, but as far as i can tell there's no
reason for the 't1' to be in this list.
(and it's not clear how the 't2s' gets
duplicated either).
any help would be appreciated,
thanks,
d
---
import sqlalchemy as rdb
USE_BACKREF = True
# Setup data
engine = rdb.create_engine('sqlite://', echo=True)
t1 = rdb.Table(
't1', engine,
rdb.Column('id', rdb.Integer, primary_key=True),
rdb.Column('selfref_id', rdb.Integer, rdb.ForeignKey('t1')),
)
t1.create()
class C1(object):
pass
m1 = rdb.mapper(C1, t1)
m1.add_property(
'selfref',
rdb.relation(C1, primaryjoin=(t1.c.id==t1.c.selfref_id),
foreignkey=t1.c.id))
t2 = rdb.Table(
't2', engine,
rdb.Column('id', rdb.Integer, primary_key=True),
rdb.Column('t1id', rdb.Integer, rdb.ForeignKey(t1.c.id)),
)
t2.create()
class C2(object):
pass
m2 = rdb.mapper(C2, t2)
# Choice of backref here
if USE_BACKREF:
m2.add_property(
't1', rdb.relation(m1, backref='t2s')
)
else:
m2.add_property(
't1', rdb.relation(m1)
)
m1.add_property(
't2s', rdb.relation(m2)
)
# Test
a = C1()
a.id = 0
for i in xrange(10):
b = C2()
b.id = i
b.t1 = a
rdb.objectstore.commit()
assert len(a.t2s) == 10
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through
log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD
SPLUNK!
http://sel.as-us.falkag.net/sel?
cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users