Oh, staring at that some more - I guess the problem is that there is nothing that says that if alice links to bob then bob links from alice. I should just defined one arc. Sorry - I will fix my code. Andrew
On Thursday, 7 February 2013 07:56:18 UTC-3, andrew cooke wrote: > > > Hi, > > Could someone please explain what the following error means? I assume I > am expecting too much magic from SQLAlchemy, but I can't see why it doesn't > "just work". > > I am trying to define a directed graph of related (music) artists. So I > have an Artist class (nodes) and a Link class (directed arcs). > > The full code is available at > https://github.com/andrewcooke/uykfg/blob/master/src/uykfg/music/db/network.pyand > > https://github.com/andrewcooke/uykfg/blob/master/src/uykfg/music/db/catalogue.pybut > I think the essential information is below: > > class Link(TableBase): > __tablename__ = 'music_links' > src_id = Column(Integer, ForeignKey(Artist.id), primary_key=True, > nullable=False) > src = relationship(Artist, backref='srcs', > primaryjoin=src_id==Artist.id) > dst_id = Column(Integer, ForeignKey(Artist.id), primary_key=True, > nullable=False) > dst = relationship(Artist, backref='dsts', > primaryjoin=dst_id==Artist.id) > > and then I ran this test: > > alice = Artist(name='alice') > session.add(alice) > bob = Artist(name='bob') > session.add(bob) > bob.srcs.append(alice) > assert len(alice.dsts) == 1, alice.dsts > > where the "append" gives the error: > > File > "/home/andrew/project/uykfg/git/env/lib/python3.2/site-packages/SQLAlchemy-0.8.0b2-py3.2.egg/sqlalchemy/orm/attributes.py", > > line 1066, in emit_backref_from_collection_append_event > child_impl = child_state.manager[key].impl > KeyError: "'src' > > Please - why? > > Thanks for reading, > Andrew > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.