arcpy.da.Describe seems to put a lock on the layer in a geodatabase. The only way to remove it seems to be closing the script. This doesn't work for me, because I need to gather info from the Describe function, and then depending on the results, move / delete the geodatabase in the same script. I tried deleting the results from the Describe function after I no longer need them, but it's just a dictionary, so it doesn't help.
Here's the basics:
aprx = arcpy.mp.ArcGISProject(path)
m = aprx.listMaps()[0]
lyrs = m.listLayers()
lyr = lyrs[0]
info = arcpy.da.Describe(lyr) # now there's a lock on the feature class that won't go away
# do some other fancy stuff here...
arcpy.management.Delete(gdb_path) # fails because there's a lock on the fc
Solved! Go to Solution.
Found a solution: use a path as the input, instead of a mapping layer object. ALSO, use arcpy.Describe instead of arcpy.da.Describe. Seems a little silly, but it works...
Found a solution: use a path as the input, instead of a mapping layer object. ALSO, use arcpy.Describe instead of arcpy.da.Describe. Seems a little silly, but it works...
I had a similar issue where using the arcpy.da module was creating a lock on my file geodatabase. I see you worked around your problem using arcpy.Describe(), but I also discovered you can use arcpy.da.Describe() so long as you use a path as the argument instead of the Layer object and also call another function that seems to force the reset, which in my case was arcpy.management.GetCount().
There seem to be two bugs here. One, when you use the Layer object as an argument to a function like Describe(), whether it's the da module or not, a lock is created that cannot be released. Two, when you use the arcpy.da module, a lock is created that can only be released if using paths to the data since using Layer objects also creates locks. See my post with additional code samples demonstrating the issues.