AnsweredAssumed Answered

Cannot use third-party IDE to debug cursors

Question asked by MollyKFoley on Sep 26, 2020
Latest reply on Sep 26, 2020 by MollyKFoley

I am trying to debug my scripts which include multiple search/update cursors in them. Any time I set a breakpoint, the cursors will not populate. If I set no breakpoints, the script runs exactly as I want it too, so it does not appear to be a coding problem.

 

I am working with Pro 2.6.1. I have tried two different IDEs, Visual Studio Enterprise 2019 version 16.7.4 and PyCharm 2019.3. I have also tried using ArcMap Python 2.7 interpreter and a regular file geodatabase instead of an SDE db to no avail.

 

These are the two different ways in which I have tried to set my breakpoints and step through the code. First, I tried to set the breakpoint before initiating the cursor and then I just step over lines until the for loop is hit. It then skips directly to the "del" statement and does not enter the for loop, even though the cursor should be selecting many features:

if int(arcpy.GetCount_management(coveyCountFL).getOutput(0)) >= 1: ### BREAKPOINT HERE ###
    with arcpy.da.UpdateCursor(coveyCountFL, ['GlobalID', 'EditingPhase', 'created_date']) as uCursor:
        for coveyCountRow in uCursor:
            coveyCountRow[1] = 'Not available for editing.'
            try:
                uCursor.updateRow(coveyCountRow)
            except:
                print(traceback.format_exc())
        del uCursor

 

If I place the breakpoint inside the for loop, it does actually stop (like it should), but then it errors when trying to update the row.

if int(arcpy.GetCount_management(coveyCountFL).getOutput(0)) >= 1:
    with arcpy.da.UpdateCursor(coveyCountFL, ['GlobalID', 'EditingPhase', 'created_date']) as uCursor:
        for coveyCountRow in uCursor:
            coveyCountRow[1] = 'Not available for editing.' ### BREAKPOINT HERE ###
            try:
                uCursor.updateRow(coveyCountRow) ### THROWS EXCEPTION HERE ###
            except:
                print(traceback.format_exc())
        del uCursor

 

Traceback (most recent call last):
File "E:\NET_Projects\CollectorGPServices\FallCoveyCount\test.py", line 63, in <module>
uCursor.updateRow(coveyCountRow)
StopIteration: iteration not started

 

As I step through the code, I have checked 

list(uCursor)

in the watch window to see what it returns. Sometimes it remains an empty list [], other times it returns things, but then if you add "coveyCountRow" in the watch window, list(uCursor) turns to [] so it seems the cursor is always empty even if it says it is not for a second.

 

I really need to be able to debug my code outside of Pro... has someone figured this issue out yet??

Outcomes