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?
Solved! Go to Solution.
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
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.
Thanks but I have other services that need write access to be editable on Collector app or through browser.
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.
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.
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.
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.
Hi @al_Dhakal
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
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
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.