Hello all,
I am trying to create a notebook that will show me all the deleted features from a hosted feature layer and put them into a spatial data frame to review, idea being we can pull from that SDF later if needed. I have the exact same script created on our "sandbox" environment on the mirrored hosted layer, however trying to set it up on the production side, I am not receiving any data back when I run the script, even when I turn on inserts and updates and have it print those accordingly (by uncommenting line 21).
My script is below, and I verified that ChangeExtraction is a capability on the target feature layer. Data I deleted was within 30 mins of the script being ran, and the change log is active for 180 days. I am worried about switching anything off then on because there are many views associated with this layer and I'm afraid of messing with all of those. Most of my research told me the servergen was the issue, but that still doesn't explain why it works perfectly fine on the sandbox version of this layer and not the production.
from arcgis.gis import GIS
from datetime import datetime, timedelta, timezone
import pandas as pd
from arcgis.features import FeatureLayerCollection
from arcgis.features import FeatureSet
gis = GIS("home")
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
flc_item = gis.content.get("<ID TO MASTER LAYER>")
flc = FeatureLayerCollection.fromitem(flc_item)
sg = flc.properties.changeTrackingInfo.layerServerGens[0].serverGen
changes = flc.extract_changes(
layers=[0],
layer_servergen = [{'id': 0, 'serverGen': sg}],
return_inserts=False,
return_updates=False,
return_deletes=True
)
# print(changes)
for i, edit in enumerate(changes.get("edits")):
layer_id = edit.get("id")
features = changes.get("edits")[i].get("features")
for op in ["deletes"]:
# print(features[op])
if op in features:
feature_dict = {
"features": [
{"attributes": feat["attributes"], "geometry": feat["geometry"]}
for feat in features[op]
]
}
feature_set = FeatureSet.from_dict(feature_dict)
feature_set.spatial_reference = {"wkid": 3857}
feature_set
feature_set.sdf