In the past, I've successfully used arcpy.TestSchemaLock prior to undertaking schema modifications within script tools. I've recently upgraded to 10.5.1 and discovered that arcpy.TestSchemaLock is now returning False when it should return True.
The example snippet below returns False in the Python window, but I can immediately add a field to the tested feature class, which indicates that it is not locked and should have returned True.
Did something get broken in 10.5.1 that worked in 10.4.1?
Thank you.
>>> fc = r'C:\Workspace\2017_Hyde\incident_data\2017_Hyde_AzCof331_Events.gdb\EventLine
>>> canGetLock = arcpy.TestSchemaLock(fc)
>>> canGetLock
False
Solved! Go to Solution.
bug http://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEwNDI4NQ==
version fixed 10.6
bug http://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEwNDI4NQ==
version fixed 10.6
Thanks. Could you re-try posting your link, please? I'm getting a "This bug does not exist" page.
http://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEwNDI4NQ== strange Jive seems to want to drop the ==
so just in case
OK, thanks.
I guess the workaround is to bracket schema lock-prone code with try: and except:
I have the same problem in 10.5.0
Thinking which function would be used without modified the dataset. Currently I get AlterField_management.
import arcpy
def isLocked(dataset):
# if arcpy.TestSchemaLock(dataset):
# return False
# else:
# return True
try:
arcpy.AlterField_management(dataset, "OBJECTID")
return False
except Exception as ex:
return True
This is a perfect workaround. Thank you!
For info...
I'm in Windows 10 now (was in Win7 previously), and arcpy.TestSchemaLock() now seems to be working in 10.5.1.