I would like to programmatically join a table to a feature class that is published as a service on ArcGIS Server 10.4.1. The problem is that the schema is locked. How can I bypass this error? When schema locking is disabled in the server manager, the error still appears.
It is not an option to programatically turn the service off while geoprocessing tasks are executed on the service.
The code below outlines where I would like to execute my join; the schema lock error is thrown at the join line.
def calculate_overdue_tickets(self):
self.logger.info("calculating overdue days for feature classes '{0}' and '{1}'".format(self.line_ticket_feature_class, self.poly_ticket_feature_class))
expression = "getDaysOverdue(!{0}!)".format(self.begin_date_field)
code_block = """def getDaysOverdue(begindate):
import datetime
if begindate is not None:
begin = datetime.datetime.strptime(begindate, '%m/%d/%Y').date()
return (datetime.date.today() - begin).days
else:
return None"""
arcpy.management.CalculateField(in_table=self.line_ticket_feature_class, field=self.days_overdue_field, expression=expression, expression_type='PYTHON_9.3', code_block=code_block)
arcpy.management.CalculateField(in_table=self.poly_ticket_feature_class, field=self.days_overdue_field, expression=expression, expression_type='PYTHON_9.3', code_block=code_block)
self.logger.info("calculating overdue status for feature classes '{0}' and '{1}'".format(self.line_ticket_feature_class, self.poly_ticket_feature_class))
expression = "getOverdueStatus(!{0}!, !{1}!, !{2}!, !{3}!)".format(self.work_status_field, self.days_overdue_field, self.origpriority_field, self.nextjobid_field)
code_block = """def getOverdueStatus(workstatus, days, origpriority, nextjobid):
if days is None:
return '{5}'
elif days < 0:
return '{0}'
elif days == 0:
return '{1}'
else:
if origpriority == '{2}':
return '{3}'
elif workstatus in ('N','P','S','A','H') and (nextjobid is not None):
return '{3}'
elif workstatus in ('N') and (nextjobid is None):
return '{4}'
else:
return '{5}'
""".format(self.status_upcoming, self.status_today, self.origpriority_value, self.status_inprogress, self.status_overdue, self.status_none)
arcpy.management.CalculateField(in_table=self.line_ticket_feature_class, field=self.overdue_status_field, expression=expression, expression_type='PYTHON_9.3', code_block=code_block)
arcpy.management.CalculateField(in_table=self.poly_ticket_feature_class, field=self.overdue_status_field, expression=expression, expression_type='PYTHON_9.3', code_block=code_block)
arcpy.JoinField_management(in_data=self.line_ticket_feature_class, in_field=self.poly_line_mobile_id, join_table= self.mobile_info_table, join_field=self.mobile_table_id)
Error:
EDIT: After a bit of testing, the join was executed correctly with the schema locking disabled in Server Manager.