Select to view content in your preferred language

How tu use dependency graph to list everything related to item

579
1
05-07-2025 06:43 AM
mikaël
Frequent Contributor

I'm playing around with the new itemgraph module trying to create a dependency graph for one service.

I was thinking that this function would list everything that uses this service, for example maps, dashboards, hosted views and joined layers/tables. But I don't think it works that way.

So let's say I create a graph for a service item that is used in a webmap:

service = "5ce9a509a99241cb921c4c10b9743f0b"
graphService = itemgraph.create_dependency_graph(gis, [service])
for i in graphService.all_items("node"):
    print("item: "+str(i.item.title)+"; type: "+str(i.item.type)+ " (id: {})".format(i.item.id))
    print("contained_by: "+str(i.contained_by()))
    print("contains: "+str(i.contained_by()))
    print("required_by: "+str(i.required_by()))
    print("requires: "+str(i.requires()))
    print("")

# item: dev actifs; type: Feature Service (id: 5ce9a509a99241cb921c4c10b9743f0b)
# contained_by: []
# contains: []
# required_by: []
# requires: [ItemNode(id: b67713a58af646d287d4405a3fdcfd24, item: gestion_actifs_export)]
#
# item: gestion_actifs_export; type: File Geodatabase (id: b67713a58af646d287d4405a3fdcfd24)
# contained_by: [ItemNode(id: 5ce9a509a99241cb921c4c10b9743f0b, item: dev actifs)]
# contains: [ItemNode(id: 5ce9a509a99241cb921c4c10b9743f0b, item: dev actifs)]
# required_by: [ItemNode(id: 5ce9a509a99241cb921c4c10b9743f0b, item: dev actifs)]
# requires: []
#

So there are 2 nodes in my graph, the first being the service itself, and the second is the FGDB from which the service was published. I thought that the webmap would be present under contained_by or required_by, which is not the case.

If I create instead the graph for the webmap:

wm = "81634afe93fa4cf0b9b6c0e645ae1dba"
graphWm = itemgraph.create_dependency_graph(gis, [wm])
for i in graphWm.all_items("node"):
    print("item: "+str(i.item.title)+"; type: "+str(i.item.type)+ " (id: {})".format(i.item.id))
    print("contained_by: "+str(i.contained_by()))
    print("contains: "+str(i.contained_by()))
    print("required_by: "+str(i.required_by()))
    print("requires: "+str(i.requires()))
    print("")

# item: dev actifs; type: Web Map (id: 81634afe93fa4cf0b9b6c0e645ae1dba)
# contained_by: []
# contains: []
# required_by: []
# requires: [ItemNode(id: b67713a58af646d287d4405a3fdcfd24, item: gestion_actifs_export), ItemNode(id: 5ce9a509a99241cb921c4c10b9743f0b, item: dev actifs)]
#
# item: dev actifs; type: Feature Service (id: 5ce9a509a99241cb921c4c10b9743f0b)
# contained_by: [ItemNode(id: 81634afe93fa4cf0b9b6c0e645ae1dba, item: dev actifs)]
# contains: [ItemNode(id: 81634afe93fa4cf0b9b6c0e645ae1dba, item: dev actifs)]
# required_by: [ItemNode(id: 81634afe93fa4cf0b9b6c0e645ae1dba, item: dev actifs)]
# requires: [ItemNode(id: b67713a58af646d287d4405a3fdcfd24, item: gestion_actifs_export)]
#
# item: gestion_actifs_export; type: File Geodatabase (id: b67713a58af646d287d4405a3fdcfd24)
# contained_by: [ItemNode(id: 5ce9a509a99241cb921c4c10b9743f0b, item: dev actifs)]
# contains: [ItemNode(id: 5ce9a509a99241cb921c4c10b9743f0b, item: dev actifs)]
# required_by: [ItemNode(id: 81634afe93fa4cf0b9b6c0e645ae1dba, item: dev actifs), ItemNode(id: 5ce9a509a99241cb921c4c10b9743f0b, item: dev actifs)]
# requires: []
#

There are 3 nodes in my graph, the first being the webmap itself, the second being the service included in the webmap and the third the FGDB.

Is this working as intended? Meaning from the webmap graph I can get the feature service, but I can't get the webmap from the feature service graph?

Thanks!

0 Kudos
1 Reply
ClaytonBurns2
Occasional Contributor

If you follow this sample you should be able to find reverse dependencies as you are looking to do. I have gotten it to work with some smaller organizations that I assist with administering, but have run into the "create_dependency_graph" function failing on my own organization when running it on all items. My organization has a lot of items and might have something corrupt that causes the function to fail?

Good luck!

Working with an Organization-Wide Dependency Graph

0 Kudos