MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / CircularDependencyError

Class CircularDependencyError

lib/sqlalchemy/exc.py:212–252  ·  view source on GitHub ↗

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; a

Source from the content-addressed store, hash-verified

210
211
212class CircularDependencyError(SQLAlchemyError):
213 """Raised by topological sorts when a circular dependency is detected.
214
215 There are two scenarios where this error occurs:
216
217 * In a Session flush operation, if two objects are mutually dependent
218 on each other, they can not be inserted or deleted via INSERT or
219 DELETE statements alone; an UPDATE will be needed to post-associate
220 or pre-deassociate one of the foreign key constrained values.
221 The ``post_update`` flag described at :ref:`post_update` can resolve
222 this cycle.
223 * In a :attr:`_schema.MetaData.sorted_tables` operation, two
224 :class:`_schema.ForeignKey`
225 or :class:`_schema.ForeignKeyConstraint` objects mutually refer to each
226 other. Apply the ``use_alter=True`` flag to one or both,
227 see :ref:`use_alter`.
228
229 """
230
231 def __init__(
232 self,
233 message: str,
234 cycles: Any,
235 edges: Any,
236 msg: Optional[str] = None,
237 code: Optional[str] = None,
238 ):
239 if msg is None:
240 message += " (%s)" % ", ".join(repr(s) for s in cycles)
241 else:
242 message = msg
243 SQLAlchemyError.__init__(self, message, code=code)
244 self.cycles = cycles
245 self.edges = edges
246
247 def __reduce__(self) -> Union[str, Tuple[Any, ...]]:
248 return (
249 self.__class__,
250 (None, self.cycles, self.edges, self.args[0]),
251 {"code": self.code} if self.code is not None else {},
252 )
253
254
255class CompileError(SQLAlchemyError):

Callers 1

sort_as_subsetsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected