youve got relationships defined on your mappers which are essentially "view only".  particularly when you specify a primaryjoin that crosses two tables, the unit of work cant do anything with that.  if you look at the flush plan (using create_session(echo_uow=True)), youll see that in the first test the Algorithm object is getting saved twice.  what you cant see (unless you add some print statements to the SA code like i did) is that its because theres essentially two sets of circular relationships between Node/Version/Project (which is something ive never even seen before...not that it isnt buggy behavior on the part of SA, but its very edge case....) and its just getting confused.

so i added for you a "view_only=False|True" flag you can add to your relation()s.  add that to all the "start_version"/"end_version" stuff since that stuff has nothing to do with what it needs to save items.

after that, the "polymorphic_identity" column is not getting assigned on insert for some reason.  

you need to break this example down into a much simpler thing first, get it to work completely, then slowly add complexity to it.  when you can isolate exactly where something stops working (like the polymorphic_identity problem), then you can send it to the list.  there is way too much going on in the current example for me to isolate how many places the mappers are getting tripped up.


On Sep 26, 2006, at 4:29 PM, Hogarty, David A. wrote:

I'm getting a strange error when flushing the session after the following sequence of creations:
 
    def test_nodes(self):
        algs = [Algorithm(name='a'+str(num)) for num in range(0,7)]
1)     params = [Parameter(name='p'+str(num)) for num in range(0,20)]
        for a in algs:
            self.db.session.save(a)
        for p in params:
            self.db.session.save(p)
        Edge(from_node=params[0],to_node=algs[0])
        Edge(from_node=params[1],to_node=algs[0])
        Edge(from_node=params[2],to_node=algs[0])
        Edge(from_node=params[1],to_node=algs[1])
        Edge(from_node=params[2],to_node=algs[1])
        Edge(from_node=params[3],to_node=algs[1])
        Edge(from_node=params[4],to_node=algs[1])
        Edge(from_node=params[4],to_node=algs[2])
        Edge(from_node=params[5],to_node=algs[2])
        Edge(from_node=params[6],to_node=algs[2])
        Edge(from_node=algs[0],to_node=params[7])
        Edge(from_node=algs[0],to_node=params[8])
        Edge(from_node=algs[1],to_node=params[9])
        Edge(from_node=algs[1],to_node=params[10])
        Edge(from_node=algs[2],to_node=params[11])
        Edge(from_node=algs[2],to_node=params[12])
        Edge(from_node=algs[2],to_node=params[13])
        Edge(from_node=params[7],to_node=algs[3])
        Edge(from_node=params[8],to_node=algs[3])
        Edge(from_node=params[9],to_node=algs[3])
        Edge(from_node=params[10],to_node=algs[3])
        Edge(from_node=params[4],to_node=algs[4])
        Edge(from_node=params[10],to_node=algs[4])
        Edge(from_node=params[11],to_node=algs[4])
        Edge(from_node=params[12],to_node=algs[4])
        Edge(from_node=params[13],to_node=algs[4])
        Edge(from_node=algs[3],to_node=params[14])
        Edge(from_node=algs[3],to_node=params[15])
        Edge(from_node=algs[4],to_node=params[16])
        Edge(from_node=params[7],to_node=algs[5])
        Edge(from_node=params[14],to_node=algs[5])
        Edge(from_node=params[15],to_node=algs[5])
        Edge(from_node=params[14],to_node=algs[6])
        Edge(from_node=params[15],to_node=algs[6])
        Edge(from_node=params[16],to_node=algs[6])
        Edge(from_node=params[13],to_node=algs[6])
        Edge(from_node=algs[5],to_node=params[17])
        Edge(from_node=algs[6],to_node=params[18])
        Edge(from_node=algs[6],to_node=params[19])
        self.db.session.flush()
        a = self.db.session.query(Algorithm).get_by_name('a4')
        assert set([p.name for p in a.inputs]) \
            == set(['p10','p4','p11','p12','p13'])
 
At some point, it tries to re-insert one of the Parameter nodes created at 1) above, initially created with
 
2006-09-26 14:53:59,192 INFO sqlalchemy.engine.base.ComposedSQLEngine.0x190cc66c
 INSERT INTO nodes (project_id, type, name, description, comments, start_version
_id, end_version_id, sub_project_id, sub_project_version_id, value, previous_id)
 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2006-09-26 14:53:59,193 INFO sqlalchemy.engine.base.ComposedSQLEngine.0x190cc66c
 [None, 2, 'p14', None, None, None, None, None, None, None, None]
 
with the following (now is inserting over the existing primary key, causing an integrity error)
 
SQLError: (IntegrityError) PRIMARY KEY must be unique 'INSERT INTO nodes (projec
t_id, id, type, name, description, comments, start_version_id, end_version_id, s
ub_project_id, sub_project_version_id, value, previous_id) VALUES (?, ?, ?, ?, ?
, ?, ?, ?, ?, ?, ?, ?)' [None, 2, 2, 'p14', None, None, None, None, None, None,
None, None]
 
Attached are two files that are a test case. You need nose to run the test: put them in the same directory and run 'nosetests' (Or manually run the setUp, test_nodes, and tearDown methods of test_db.py:TestRelateDB).
On re-running the test case before sending, I found that it has several different possible results. I included four output files from recent runs to demonstrate. All of these runs are with the attached code.
 
Any help would be much appreciated,
 
-Dave H
 
 
<test.tar.gz>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
Sqlalchemy-users mailing list

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to