Skip to content

Instantly share code, notes, and snippets.

@prescod
Created June 13, 2022 09:53
Show Gist options
  • Save prescod/3ceb6b69f9c6892c87bda7e449ba99cf to your computer and use it in GitHub Desktop.
Save prescod/3ceb6b69f9c6892c87bda7e449ba99cf to your computer and use it in GitHub Desktop.
Use CumulusCI and NetworkX to find reference cycles
# cci org shell qa --script find_cycles.py
import networkx
from cumulusci.salesforce_api.org_schema import get_org_schema
def look_for_cycles(sf, org_config):
G = networkx.DiGraph()
with get_org_schema(sf, org_config) as org_schema:
for sobject in org_schema.sobjects:
if not sobject.createable:
continue
for field in sobject.fields.values():
for target in field.referenceTo:
if not field.createable:
continue
G.add_edge(sobject.name, f"{sobject.name}.{field.name}")
G.add_edge(f"{sobject.name}.{field.name}", target)
cycles = tuple(networkx.simple_cycles(G))
for cycle in cycles:
print(cycle)
look_for_cycles(sf, org_config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment