diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-09-23 22:17:18 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-09-23 22:17:18 -0400 |
commit | 9d842790b40717d35195d7ed23dd1c151430c347 (patch) | |
tree | 9dcbafb35283c0f8853fece7fcfcadc86d7142a8 | |
parent | c52e31b1e019fb447e0a2edb7e2c75ebe9307a95 (diff) | |
download | sqlalchemy-9d842790b40717d35195d7ed23dd1c151430c347.tar.gz |
document CircularDependencyError. [ticket:2285]
-rw-r--r-- | doc/build/core/schema.rst | 2 | ||||
-rw-r--r-- | doc/build/orm/relationships.rst | 1 | ||||
-rw-r--r-- | lib/sqlalchemy/exc.py | 19 | ||||
-rw-r--r-- | lib/sqlalchemy/util/topological.py | 2 |
4 files changed, 21 insertions, 3 deletions
diff --git a/doc/build/core/schema.rst b/doc/build/core/schema.rst index 78fa6ee9c..21fcf1648 100644 --- a/doc/build/core/schema.rst +++ b/doc/build/core/schema.rst @@ -925,6 +925,8 @@ would not be aware that these two values should be paired together - it would be two individual foreign key constraints instead of a single composite foreign key referencing two columns. +.. _use_alter: + Creating/Dropping Foreign Key Constraints via ALTER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/build/orm/relationships.rst b/doc/build/orm/relationships.rst index fa46d0ba1..a506fc7f3 100644 --- a/doc/build/orm/relationships.rst +++ b/doc/build/orm/relationships.rst @@ -966,6 +966,7 @@ to complement the ``boston_addresses`` attribute: addresses_table.c.city=='New York')), }) +.. _post_update: Rows that point to themselves / Mutually Dependent Rows ------------------------------------------------------- diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py index 0cc52fd25..c76f68d21 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -27,9 +27,24 @@ class ArgumentError(SQLAlchemyError): class CircularDependencyError(SQLAlchemyError): - """Raised by topological sorts when a circular dependency is detected""" + """Raised by topological sorts when a circular dependency is detected. + + There are two scenarios where this error occurs: + + * In a Session flush operation, if two objects are mutually dependent + on each other, they can not be inserted or deleted via INSERT or + DELETE statements alone; an UPDATE will be needed to deassociate + one of the foreign key constraints first. The ``post_update`` flag + described at :ref:`post_update` can resolve this cycle. + * In a :meth:`.MetaData.create_all`, :meth:`.MetaData.drop_all`, + :attr:`.MetaData.sorted_tables` operation, two :class:`.ForeignKey` + or :class:`.ForeignKeyConstraint` objects mutually refer to each + other. Apply the ``use_alter=True`` flag to one or both, + see :ref:`use_alter`. + + """ def __init__(self, message, cycles, edges): - message += ": cycles: %r all edges: %r" % (cycles, edges) + message += " Cycles: %r all edges: %r" % (cycles, edges) SQLAlchemyError.__init__(self, message) self.cycles = cycles self.edges = edges diff --git a/lib/sqlalchemy/util/topological.py b/lib/sqlalchemy/util/topological.py index ba68b7136..a5efa6388 100644 --- a/lib/sqlalchemy/util/topological.py +++ b/lib/sqlalchemy/util/topological.py @@ -28,7 +28,7 @@ def sort_as_subsets(tuples, allitems): if not output: raise CircularDependencyError( - "Circular dependency detected", + "Circular dependency detected.", find_cycles(tuples, allitems), _gen_edges(edges) ) |