Hello everyone,
I am getting the following error after running my script:

The script runs fine when I am not in a version but once I change it to a version, it breaks after the first UpdateCursor. Note: the imported "cursors" module is from this post: https://community.esri.com/t5/python-questions/the-requested-operation-is-invalid-on-a-closed-state/m-p/343774
import arcpy
import datetime
import cursors
import os
def calcNorthing():
# userInput_Layer = "{}_Layer".format(userInput)
# arcpy.MakeFeatureLayer_management(userInput, userInput_Layer)
try:
# calculate northing
if 'Northing' not in lstFields:
arcpy.AddField_management(userInput, "Northing", "DOUBLE")
print("Calculating Northing Field")
arcpy.AddMessage("Calculating Northing Field")
with cursors.UpdateCursor(userInput, ['Northing', 'Shape@'], "Northing IS NULL") as cursor:
for row in cursor:
if row[1] is not None:
pt = row[1].projectAs('2236').centroid
row[0] = round(pt.Y, 3)
cursor.updateRow(row)
print("Completed Northing calculation")
arcpy.AddMessage("Completed Northing calculation")
# del cursor
except():
arcpy.AddMessage("Failed Northing calculation.")
# finally:
def calcEasting():
try:
# calculate easting
if 'Easting' not in lstFields:
arcpy.AddField_management(userInput, "Easting", "DOUBLE")
print("Calculating Easting Field")
arcpy.AddMessage("Calculating Easting Field")
with cursors.UpdateCursor(userInput, ['Easting', 'Shape@'], "Easting IS NULL") as cursor:
for row in cursor:
if row[1] is not None:
pt = row[1].projectAs('2236').centroid
row[0] = round(pt.X, 3)
cursor.updateRow(row)
except():
arcpy.AddMessage("Failed Easting calculation.")
finally:
print("Completed Easting calculation")
arcpy.AddMessage("Completed Easting calculation")
def calcLongitude():
try:
# calculate longitude
if 'Longitude' not in lstFields:
arcpy.AddField_management(userInput, "Longitude", "DOUBLE")
print("Calculating Longitude Field")
arcpy.AddMessage("Calculating Longitude Field")
with cursors.UpdateCursor(userInput, ['Longitude', 'Shape@'], "Longitude IS NULL or Longitude < -82") as cursor:
for row in cursor:
if row[1] is not None:
pt = row[1].projectAs('4326').centroid
row[0] = round(pt.X, 6)
cursor.updateRow(row)
finally:
print("Completed Longitude calculation")
arcpy.AddMessage("Completed Longitude calculation")
def calcLatitude():
try:
# calculate latitude
if 'Latitude' not in lstFields:
arcpy.AddField_management(userInput, "Latitude", "DOUBLE")
print("Calculating Latitude Field")
arcpy.AddMessage("Calculating Latitude Field")
with cursors.UpdateCursor(userInput, ['Latitude', 'Shape@'], "Latitude IS NULL or Latitude < 0") as cursor:
for row in cursor:
if row[1] is not None:
pt = row[1].projectAs('4326').centroid
row[0] = round(pt.Y, 6)
cursor.updateRow(row)
finally:
print("Completed Latitude calculation")
arcpy.AddMessage("Completed Latitude calculation")
def calcSLOCSEQ():
try:
# calculate SERVICE_LOC_SEQ
if 'S_LOC_SEQ' in lstFields:
print("Calculating SERVICE_LOC_SEQ")
arcpy.AddMessage("Calculating SERVICE_LOC_SEQ")
with cursors.UpdateCursor(userInput, ['S_LOC_SEQ', 'METER_NUMB']) as cursor:
for row in cursor:
if row[1] is None:
print ("Bad value")
elif row[1].isnumeric():
row[0] = row[1]
# row[7] = datetime.datetime.now()
cursor.updateRow(row)
else:
print("Field does not exist.")
arcpy.AddMessage("Field does not exist. No calculation performed.")
finally:
arcpy.AddMessage("Completed SERVICE_LOC_SEQ calculation")
def calcDuplicates():
try:
if 'METER_NUMB' in lstFields:
arcpy.AddMessage("Searching for Duplicates. A value more than 1 in the \"Point_ID\" field represents number of duplicae values")
infeature = userInput
field_in = 'METER_NUMB'
field_out = 'Point_ID'
# creating the list with all the values in the field, including duplicates
lista = []
with arcpy.da.SearchCursor(infeature, ['METER_NUMB']) as cursor1:
for row in cursor1:
lista.append(row[0])
# updating the count field with the number on occurrences of field_in values
# in the previously created list
cursor2 = arcpy.UpdateCursor(infeature)
for row in cursor2:
i = row.getValue(field_in)
occ = lista.count(i)
row.setValue(field_out, occ)
cursor2.updateRow(row)
del cursor2
del row
print("Done.")
else:
print("METER_NUMB field does not exist. No duplicate check performed.")
except():
arcpy.AddMessage("Calculating duplicate process failed")
finally:
arcpy.AddMessage("Completed duplicate calculation")
if __name__ == '__main__':
startTime = datetime.datetime.now().replace(microsecond=0)
print("Operation started on {}".format(startTime))
arcpy.AddMessage("Operation started on {}".format(startTime))
arcpy.env.overwriteOutput = True
userInput = arcpy.GetParameterAsText(0) #point data here
lstFields = [f.name for f in arcpy.ListFields(userInput)]
calcNorthing()
calcEasting()
calcLongitude()
calcLatitude()
calcSLOCSEQ()
calcDuplicates()
arcpy.SelectLayerByAttribute_management(userInput, "CLEAR_SELECTION") #attempt to refresh table
endTime = datetime.datetime.now().replace(microsecond=0)
dur = endTime - startTime
dur = str(dur)
print('Duration: {}'.format(dur))
arcpy.AddMessage('Duration: {}'.format(dur))