Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Finding circular dependencies in your SQLAlchemy data scheme
from collections import defaultdict
dependencies = defaultdict(set)
#use your metadata object here
for t in metadata.sorted_tables:
for fkey in t.foreign_key_constraints:
def find_circular_dependencies(dependencies,verbose = False):
def walk_graph(name,path = None,tabs = 0):
if path is None:
path = []
for dependency in dependencies[name]:
if verbose:
print " "*tabs,dependency
if dependency in path:
print "Circular dependency:","->".join(path+[dependency])
walk_graph(dependency,path+[dependency],tabs = tabs+1)
for name in dependencies.keys():
#will print your circular dependencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.