Geoprocessing Service not seeing newly added data unless restarted or republished?

1489
1
11-05-2014 10:56 AM
DominickAlfonso
New Contributor

I have a Geoprocessing Service that is complicated, but the issue I'm having revolves around a few very simple steps. I'm trying to take in a path to a feature class that sits within SDE, create a temporary feature layer out of it (arcpy.MakeFeatureLayer_management), and then use a search cursor (arcpy.da.SearchCursor) to count the records in the feature class. I am not using ArcMap or anything outside of arcpy for this, the layer is stored in-memory and dumped after being used. The script itself works fine up until the point that new data is added and then the results become inconsistent with the actual data.

Here is an example of the issue:

  1. Feature Class has 0 records.
  2. The Model behind the Geoprocessing Service is run through ArcCatalog/ArcMap and returns a count of "0 records found." (OK)
  3. The Geoprocessing Service itself also returns "0 records found." (OK)
  4. 1 record is added to the Feature Class through some means in an edit session (programatically, through ArcMap, etc.)
  5. The model behind the Geoprocessing Service is run through ArcCatalog/ArcMap and still returns a count of "0 records found." (INCORRECT)
  6. The Geoprocessing Service itself also returns "0 records found." (INCORRECT)

The only way I've discovered that the model will display the correct record count when run from Desktop is to close/open all ArcGIS Desktop applications and re-run it. Likewise, for the Geoprocessing Service to display the correct record count, I must restart or republish the Geoprocessing Service.

I'm hoping this issue has a simple resolution, but I'm scratching my head over it as of right now. If someone needs sample code, I can provide it, but the first paragraph is the script in a nutshell.

0 Kudos
1 Reply
DallasShearer
Occasional Contributor

I suspect the issue is with the SearchCursor not being disposed of on completion of it's duties. if you aren't preceding the search cursor with a "with" like this:

with arcpy.da.SearchCursor(fc, fields) as cursor:

then you'll need to be sure to do del on the variable assigned to the cursor. like this

cursor = arcpy.da.SearchCursor(fc, fields)

for row in cursor:

     ...

del cursor

you can also try in the same script simultaneously to get the count using arcpy.GetCount_management(fc) to see if the issue is with the cursor or with the connection.

here's a link to the getcount_management help page: ArcGIS Desktop

0 Kudos