Select to view content in your preferred language

FeatureLayerCollection.replicas.create always returns the correct tables but 0 records in the tables

297
2
yesterday
Labels (2)
Trippetoe
Frequent Contributor

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:

  • Using the AGOL Item Details page to Export as file geodatabase.
  • A direct query on layer 0 returns the expected 27 records
  • Running createReplica manually via the REST Services Directory HTML form returns the expected number of records

What I've have tried (all returning 0 rows):

  • syncModel=none with no geometry filter
  • syncModel=none with geometry set to the service's full extent
  • Adding layerQueries with where=1=1, useGeometry=false, includeRelated=true, queryOption=useFilter for both layers
  • syncDirection=bidirectional
  • geometryType=esriGeometryPoint
  • async=true and async=false
  • layers as comma-separated string (0,1) and as JSON array ([0,1])
  • using an empty querylayers
  • using a populated queryLayers with filter set to 1=1

Any thoughts on how to get the expected number of records returned?

2 Replies
KenGalliher1
Esri Contributor

@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?

0 Kudos
KenGalliher1
Esri Contributor

@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()
0 Kudos