1

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:

enter image description here

EDIT: After a bit of testing, the join was executed correctly with the schema locking disabled in Server Manager.

4
  • To confirm, are you trying to join to the feature class, or the service itself?
    – Midavalo
    Commented Oct 3, 2016 at 17:45
  • joining to feature class Commented Oct 3, 2016 at 17:45
  • I see you've got it working, that's great! Did you have to change anything, or did it just happen (something released a lock)? If you had to change something I'd suggest you should post your solution as an answer to your question
    – Midavalo
    Commented Oct 3, 2016 at 18:41
  • 1
    It is unwise to modify the structure of tables which are actively being used by ArcGIS Server. The locks are placed to prevent corruption. Defeating the locks does not reduce the risk; in fact, service corruption and database corruption are far more likely.
    – Vince
    Commented Oct 4, 2016 at 0:02

1 Answer 1

1

The Join Field tool modifies the existing feature class by adding the joined fields to it. This is why you get a schema lock error. Only use this tool if you actually want to permanently modify your feature class.

A typical join (similar to if you right-click a layer in ArcMap) is performed in arcpy by using the Add Join tool. This performs the join in memory.


If you are trying to update the schema with schema locking disabled, there may be something else locking your feature class. See the note on Disabling schema locking on a map service which says:

Even when you disable schema locking in a map service, other ArcGIS applications and services may still be able to obtain exclusive locks to the schema. If you are unable to update the schema of the dataset after disabling schema locking, see Schema locking. This topic contains information that can help you understand how locks may be preventing you from updating the schema.

5
  • This is a standalone script; I am using a layer or table view which are acceptable data types for AddJoin, I would like to permanently change the feature class, so that is not the issue. Commented Oct 3, 2016 at 18:04
  • By permanently modify the feature class I mean it actually adds all the fields from the join table. It doesn't just update existing fields.
    – Midavalo
    Commented Oct 3, 2016 at 18:06
  • I am aware; this is the desired output, I have tested this with the service being turned off and it works correctly; I just need to modify the feature class while the service is turned on. Commented Oct 3, 2016 at 18:08
  • @GeoffreyWest I have updated my answer
    – Midavalo
    Commented Oct 3, 2016 at 18:14
  • 1
    @GeoffreyWest please edit your question to include the extra info that you are wanting the join to modify the schema
    – Midavalo
    Commented Oct 3, 2016 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.