Hi there. I have a python script that attempts to export a hosted feature service as a file geodatabase using the python api's featurelayercollection.replicas.create() method. I am running python 3.11.10 and arcgis api 2.3.0
The service details:
- One feature layer (id: 0, geometry type: point) with attachments
- One related table (id: 1) with attachments
- Sync is enabled
- supportsSyncModelNone = true
The problem:
the replicas.create() operation consistently returns a file geodatabase with the correct schema but 0 rows in all tables, regardless of parameters used.
What works:
What I've have tried (all returning 0 rows):
Any thoughts on how to get the expected number of records returned?
@Trippetoe This is a great question. I'm looking into it now. Can you provide a code snippet that shows how you are setting up the replica? What are the sync options, geometry and layer queries look like?
@Trippetoe I was not able to reproduce the missing rows with a file geodatabase or SQLite geodatabase. Here is the code I used. Let me know if you have any questions.
import time
import tempfile
from arcgis.features.layer import FeatureLayerCollection
from arcgis.gis import GIS
from arcgis import geometry
gis = GIS(profile="your_online_profile")
item = gis.content.get("401876e7f782419dbd29974ce8a4e11b")
flc = FeatureLayerCollection(item.url, gis)
output_gdb_path = tempfile.TemporaryDirectory()
service_url = flc.url
extent = {
"xmin": -13238397.099502765,
"ymin": 3923105.9219284547,
"xmax": -13037402.432768419,
"ymax": 4065046.3578960407,
}
geom_filter = geometry.filters.envelope_intersects(extent)
sync_options = {"syncDataOptions": 260}
layer_queries = {
"0": {"queryOption": "useFilter", "useGeometry": True},
"2": {"queryOption": "useFilter", "useGeometry": False},
}
# For file gdb, the sync model must be none
# For mobile gdb, use "perLayer" or "perReplica"
sync_model = "none"
data_format = "filegdb"
replica_options = {
"replica_name": f"ReplicaTest_{int(time.time())}",
"layers": [0, 2],
"layer_queries": layer_queries,
"geometry_filter": geom_filter,
"replica_sr": {"wkid": 102642, "latestWkid": 2226},
"transport_type": "esriTransportTypeUrl",
"return_attachments": True,
"attachments_sync_direction": "bidirectional",
"sync_model": sync_model,
"data_format": data_format,
"replica_options": sync_options,
"out_path": output_gdb_path.name,
"sync_direction": "bidirectional",
}
try:
res = flc.replicas.create(**replica_options)
print(res)
except Exception as ex:
print("Create Replica failed:", str(ex))
finally:
output_gdb_path.cleanup()