Hi all,
I'm having some trouble defining cyclical FK references in my models.
I understand from the documentation that specifying post_update=True
on the relation definition should effectively remove that edge from
the dependency graph.

However, the following code still gives CircularDependencyErrors
(stack trace at the end) -- this is SA 0.4.2p3:
tableA = Table('tableA', metadata,
    Column('a_id', Integer, primary_key=True),
    Column('b_id', Integer, ForeignKey('tableB.b_id',
        onupdate="CASCADE", ondelete="CASCADE")),
    mysql_engine='InnoDB'
)

tableB = Table('tableB', metadata,
    Column('b_id', Integer, primary_key=True),
    Column('a_id', Integer, ForeignKey('tableA.a_id',
        onupdate='CASCADE', ondelete='CASCADE')),
    mysql_engine="InnoDB"
)

class A(object):
    pass

class B(object):
    pass

mapper(A, tableA,
    properties=dict(
        b = relation(B)
    )
)

mapper(B, tableB,
    properties = dict(
        a = relation(A, post_update=True)
    )
)

Any suggestions on how to tackle this?

Thanks a lot!
James

------------ Stack Trace -------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/Current/bin/tg-
admin", line 8, in <module>
    load_entry_point('TurboGears==1.0.4.2', 'console_scripts', 'tg-
admin')()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/TurboGears-1.0.4.2-py2.5.egg/turbogears/
command/base.py", line 371, in main
    command.run()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/TurboGears-1.0.4.2-py2.5.egg/turbogears/
command/base.py", line 97, in run
    sacommand(command, sys.argv)
  File "<string>", line 5, in sacommand
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/TurboGears-1.0.4.2-py2.5.egg/turbogears/
command/sacommand.py", line 33, in create
    metadata.create_all()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SQLAlchemy-0.4.2p3-py2.5.egg/sqlalchemy/
schema.py", line 1215, in create_all
    bind.create(self, checkfirst=checkfirst, tables=tables)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SQLAlchemy-0.4.2p3-py2.5.egg/sqlalchemy/engine/
base.py", line 1131, in create
    self._run_visitor(self.dialect.schemagenerator, entity,
connection=connection, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SQLAlchemy-0.4.2p3-py2.5.egg/sqlalchemy/engine/
base.py", line 1160, in _run_visitor
    visitorcallable(self.dialect, conn, **kwargs).traverse(element)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SQLAlchemy-0.4.2p3-py2.5.egg/sqlalchemy/sql/
visitors.py", line 76, in traverse
    meth(target)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SQLAlchemy-0.4.2p3-py2.5.egg/sqlalchemy/sql/
compiler.py", line 758, in visit_metadata
    collection = [t for t in metadata.table_iterator(reverse=False,
tables=self.tables) if (not self.checkfirst or not
self.dialect.has_table(self.connection, t.name, schema=t.schema))]
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SQLAlchemy-0.4.2p3-py2.5.egg/sqlalchemy/
schema.py", line 1133, in table_iterator
    return iter(sort_tables(tables, reverse=reverse))
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SQLAlchemy-0.4.2p3-py2.5.egg/sqlalchemy/sql/
util.py", line 19, in sort_tables
    sequence = topological.sort(tuples, tables)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SQLAlchemy-0.4.2p3-py2.5.egg/sqlalchemy/
topological.py", line 32, in sort
    return [n.item for n in _sort(tuples, allitems,
allow_cycles=False, ignore_self_cycles=True)]
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SQLAlchemy-0.4.2p3-py2.5.egg/sqlalchemy/
topological.py", line 216, in _sort
    raise CircularDependencyError("Circular dependency detected " +
repr(edges) + repr(queue))
sqlalchemy.exceptions.CircularDependencyError: Circular dependency
detected [(tableA, tableB), (tableB, tableA)][]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to