Publishing a layer creates lock and my python script cannot replace the feature class

942
11
Jump to solution
11-04-2021 11:49 AM
ShitalDhakal
New Contributor II

Hello, I get a fresh csv every morning that I geocode and publish as a feature layer to be consumed in a dashboard. Now when I use python script to automate the workflow every morning, I see a lock from my ArcGIS Server service account. This lock (probably) doesn't let the python to overwrite the feature and a result, the new feature class that gets created appears in UPPER CASE and as a stand alone layer (not inside feature dataset). From second time around, the script just fails because either it couldn't overwrite the feature class or because it thinks there is already a feature class with that name inside the enterprise geodatabase. 

So, basically how can I overwrite a feature class that is published and hence has a lock from service account using python?   

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
ShitalDhakal
New Contributor II

Hi all, thank you for all the suggestions. The easier solution that worked for my (as of now) is to use the database view and publish the view layer instead. This way, there is a lock established on the view feature class only and I can use python scripts to overwrite the original feature class. More on the database view here - https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/create-database-view.htm

View solution in original post

0 Kudos
11 Replies
Scott_Tansley
Regular Contributor

Assuming your data is not on the c: you can change the permissions of the server service account to read only.  Then it can’t create locks. 

Scott Tansley
Consulting Architect (ArcGIS Enterprise)
https://www.linkedin.com/in/scotttansley/
ShitalDhakal
New Contributor II

Thanks but I have other services that need write access to be editable on Collector app or through browser. 

0 Kudos
RyanBohan
Occasional Contributor III

Hi Shital, 

  I am fairly new to python myself.  I did find a tutorial on YouTube that really helped.  https://www.youtube.com/watch?v=NfnBLGLRb7Q

I also found making a view of my feature layer to share with the public helped once it's published.

ShitalDhakal
New Contributor II

Thank you. I will look into this. Although mine is not a hosted layer. It's a feature layer published through federated server so that the layer is always in sync with the enterprise geodatabase. 

0 Kudos
by Anonymous User
Not applicable

It all depends on how you have it set up but a truncate and load will work even with locks.  Keep the existing table and just replace the data.

 

ShitalDhakal
New Contributor II

I will look into this, thank you. I am also trying to see if creating a 'database view' and publishing the view layer might release lock from my actual feature class. 

0 Kudos
IhabHassan
Esri Contributor

Hi @ShitalDhakal 
instead of republishing the service every time you get new data, you can use the feature access capability to update the service features. 
I would recommend having a look into this tutorial, implementing almost exactly what you are after:

Append attribute values from a CSV into a new column on a Feature Layer
https://developers.arcgis.com/python/guide/appending-features/#Append-attribute-values-from-a-CSV-to...

 

Hope that helps

Ihab

Regards
Ihab
IhabHassan
Esri Contributor

Alternative approach, while still using the service, is to use API for Python arcgis.features.FeatureLayer module, either using the "append" or "edit_features" methods, as explained here:
https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#featurelayer

Regards
Ihab
0 Kudos
ShitalDhakal
New Contributor II

Thank you. Append might not work for what I am trying to do because I want to add all the records every morning and delete all the records from the previous day.  

0 Kudos