I’m trying to represent a graph with nodes and edges…
For the nodes I’m using polymorphic single-table inheritance. The
relevant mapping & code is: # Mapper classes: # # Project # # Node # -> Algorithm # -> Parameter # # Edge # Project.nodes ->
Node
(->N) # Project <-
Node.project (0,1<-) # Project.edges ->
Edge
(->N) # Project <-
Node.project (0,1<-) # Node.inputs ->
Edge
(->N) # Node
<- Edge.to_node (0,1<-) # Node.outputs ->
Edge
(->N) # Node
<- Edge.from_node (0,1<-) # Algorithm.sub_project -> Project
(->0,1) #
Algorithm
<- Project.alg_nodes_using (N<-) def make_graph_small(self): p =
Project(name='small')
self.db.session.save(p) algs =
[Algorithm(name='a'+str(num)) for num in range(0,2)] params =
[Parameter(name='p'+str(num)) for num in range(0,8)] for a in
algs+params:
self.db.session.save(a)
p.nodes.append(a) for i in
[0,1,2,3]:
Edge(from_node=params[i],to_node=algs[0]) for i in [4,5]:
Edge(from_node=algs[0],to_node=params[i]) for i in [6,7]:
Edge(from_node=algs[1],to_node=params[i])
Edge(from_node=params[5],to_node=algs[1])
self.db.session.flush() on the flush, the project gets inserted twice, causing a
primary key error. Attached file: test.tar.gz: -> db.py :
Schema/Mapper definitions -> test_db.py :
Test that’s breaking -> project_pkey_error : Output with
logging enabled from test run Any help in figuring out why this is occurring would be
great, -Dave H |
test.tar.gz
Description: 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 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