Error on updateRow or deleteRow

2974
4
04-14-2016 10:26 AM
SteveClark
New Contributor III

I have relatedtable in sde that I want to insert or update/delete a row. I am able to insertRow fine but I am not able to execute updateRow or deleteRow on the cursor. There is always: SystemError: error return without exception set

Here's the pertinent part of the code:

tableFields = ['LID', 'OperatedBy', 'GPSPositions', 'Turns', 'OperationDate', 'Longitude', 'Latitude', 'HighTorque', 'BeginTime', 'Remarks', 'Position', 'EndTime']
insValues = [u'W.285489', u'Roy P.', None, 88.2, datetime.datetime(2015, 2, 19, 0, 0), None, None, 50, u'11:55 AM', u'PAVD,VAC', u'Open', u'12:00 PM']
if tableCount == 0: # Insert - THIS WORKS FINE
    editor.startOperation() 
    with arcpy.da.InsertCursor(tablePath, tableFields) as insCursor:
        insCursor.insertRow(insValues)
    editor.stopOperation()
    saveEdits = True
else: # Update
    editor.startOperation() 
    with arcpy.da.UpdateCursor(tablePath, tableFields, lidQuery) as updCursor:
        for updRow in updCursor: # ALWAYS RETURNS THE ONE ROW THAT I WANTED TO UPDATE OR DELETE
            updRow = insValues
            updCursor.updateRow(updRow) # - ERROR
            # ALSO JUST UPDATING ONE VALUE - SAME ERROR
            # updRow[0] = 'W.999999'
            # updCursor.updateRow(updRow)
    # OR I could deleteRow and then do an insertRow - SAME ERROR
    #    for updRow in updCursor:
    #        updCursor.deleteRow()
    editor.stopOperation() 
    saveEdits = True

As far as I can tell, the updCursor returns what I want - the row that I want to update or delete. But no matter what I do with that cursor, I get

Traceback (most recent call last):
  File "<pyshell#89>", line 1, in <module>
    updCursor.deleteRow()
SystemError: error return without exception set

or simply "error return without exception set"

What am I doing wrong with the UpdateCursor?

(This is ArcMap 10.2.1.)

0 Kudos
4 Replies
AdrianWelsh
MVP Honored Contributor

Steve, would it help if you posted the entire segment of code so we can see where different variables are being instantiated?

0 Kudos
SteveClark
New Contributor III

Here's the entire code as I have progressed so far:

import arcpy
import os
import sys
import datetime
inputFC = "WLINEVALVE"
tableFields = ['LID', 'OperatedBy', 'GPSPositions', 'Turns', 'OperationDate', 'Longitude', 'Latitude', 'HighTorque', 'BeginTime', 'Remarks', 'Position', 'EndTime']
insValues = [u'W.285489', u'Roy P.', None, 88.2, datetime.datetime(2015, 2, 19, 0, 0), None, None, 50, u'11:55 AM', u'PAVD,VAC', u'Open', u'12:00 PM']
try:
    dbConnection = r'Database Connections\conn.sde'  
    workspace = os.path.dirname(dbConnection)
    editor = arcpy.da.Editor(workspace)
    saveEdits = False
    editor.startEditing(False, True)
    fcPath = dbConnection + "\\" + inputFC 
    tableName = "ARCFM." + inputFC + "RELTABLE_EVW"
    tablePath = dbConnection + "\\" + tableName
    # hardcoding for test
    lidQuery = "{0} = {1}".format("LID", "'W.285489'")
    with arcpy.da.SearchCursor(fcPath, ['*'], lidQuery) as fcCursor:
        try:
            fcLID = fcCursor.next() # will throw StopIteration if empty
            if fcLID != None: 
                tableCount = 0
                with arcpy.da.SearchCursor(tablePath, ['*'], lidQuery) as tableCursor:
                    for tableLID in tableCursor:
                        tableCount += 1
                # if no count, do Insert; else do Update
                if tableCount == 0: # Insert
                    editor.startOperation() 
                    with arcpy.da.InsertCursor(tablePath, tableFields) as insCursor:
                        insCursor.insertRow(insValues)
                        del insValues  
                    editor.stopOperation()
                    saveEdits = True
                else: # Update
                    editor.startOperation() 
                    with arcpy.da.UpdateCursor(tablePath, tableFields, lidQuery) as updCursor:
                        for updRow in updCursor: # ALWAYS RETURNS THE ONE ROW THAT I WANTED TO UPDATE OR DELETE
                            updRow = insValues
                            updCursor.updateRow(updRow) # - ERROR
                                # ALSO JUST UPDATING ONE VALUE - SAME ERROR
                                # updRow[0] = 'W.999999'
                                # updCursor.updateRow(updRow)
                        # OR I could deleteRow and then do an insertRow - SAME ERROR
                        #    for updRow in updCursor:
                        #        updCursor.deleteRow()
                        editor.stopOperation() 
                        saveEdits = True
            else: 
                print 'LID not valid, ignore for now = abort operation'
                editor.abortOperation()
            del fcLID
        except StopIteration:  # if no LID in featureclass
            print 'LID not valid, ignore for now = abort operation'
            editor.abortOperation()
except Exception as ex:  
    print 'Error: ' + str(ex) + ' = abort operation'
    editor.abortOperation()  
finally: 
    if saveEdits: 
        print 'Stop Editing and Save'
        editor.stopEditing(True) 
    else: 
        print 'Stop Editing and Not Save'
        editor.stopEditing(False)
0 Kudos
TomaszTARCHALSKI1
Esri Contributor

Hi,

when inserting - I think you need to insert tuple, not the list. Try this one: updCursor.updateRow(tuple(insValues)).

0 Kudos
SteveClark
New Contributor III

I updated line 40 in the code above

insValues = [u'W.285489', u'Roy P.', None, 88.2, datetime.datetime(2015, 2, 19, 0, 0), None, None, 50, u'11:55 AM', u'PAVD,VAC', u'Open', u'12:00 PM']
                    with arcpy.da.UpdateCursor(tablePath, tableFields, lidQuery) as updCursor:
                        for updRow in updCursor:
                            updRow = insValues
                            updCursor.updateRow(tuple(updRow))

and still got the same error.

I wonder what's the difference between insertRow and updateRow when I am using the same insValues list. insertRow works fine but not updateRow.

0 Kudos