Mike Bayer avatar Mike Bayer committed 0f14385

document CircularDependencyError. [ticket:2285]

Comments (0)

Files changed (4)

doc/build/core/schema.rst

 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
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

doc/build/orm/relationships.rst

                     addresses_table.c.city=='New York')),
     })
 
+.. _post_update:
 
 Rows that point to themselves / Mutually Dependent Rows
 -------------------------------------------------------

lib/sqlalchemy/exc.py

 
 
 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

lib/sqlalchemy/util/topological.py

 
         if not output:
             raise CircularDependencyError(
-                    "Circular dependency detected",
+                    "Circular dependency detected.",
                     find_cycles(tuples, allitems), 
                     _gen_edges(edges)
                 )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.