Select to view content in your preferred language

RuntimeError: Function requires a state to be set for stream

5535
3
Jump to solution
03-14-2013 10:39 AM
StormwaterWater_Resources
Regular Contributor
ArcStandard 10.1, versioned editing, remote SDE 10.0 on MS SQL, Win7-64, python 2.7, editing line fc of geometric network

RuntimeError: Function requires a state to be set for stream [...sde path to fc...][STATE_ID = 0]

Failed on a cursor update (rows.updateRow(row))  (not sure if it's relevant where it failed though)

I'm stepping through lines and copying data to the line from points intersecting the endpoints of the line.  I'm running this against a little more than 4000 lines.  The above error popped up after processing the 513th line.  After the above error I copied the entire geometric network to a local file GDB, ran the same script, at it successfully completed all 4000+ lines.

Suggestions?

PS: the script runs from my ArcMap project so I just realized I may have posted this to the wrong forum.  Can someone comment on that too?
0 Kudos
1 Solution

Accepted Solutions
StormwaterWater_Resources
Regular Contributor
Just to close this out I'll reply to my own post.  I had been performing edits without initiating an edit session in the script.  Instead I started editing manually (Edit menu -> Start Editing), and then started the script.  This works without problems on an unversioned file GDB, but on a versioned SDE it fails.  The solution was to start the edit session within the script (and NOT start editing manually prior to starting the script).  See this Esri page for details:   Editor (arcpy.da) (Note: as of Apr 9, 2013 this page has a typo in example 2 at the bottom: the startEditing and startOperation call order is reversed, it should be startEditing first and then startOperation).

Some additional notes:  To run this from an active ArcMap session you need to get the edit layer's workspacePath.  For reasons I still don't understand if I change the version of a layer in the source tab of the Table of Contents the layer loses its workspacePath value.  Creating a database connection to your version of the SDE and loading layers from there seems to mitigate this issue (since you don't have to change the version).  Thus the pertinent code is as follows:

import arcpy, os  layerName  = arcpy.GetParameterAsText(0)                                   # Set script parameter as type Feature Layer mxd        = arcpy.mapping.MapDocument("CURRENT")                          # assuming one data frame layer      = arcpy.mapping.ListLayers(mxd, os.path.basename(layerName))[0] # basename strips off a ToC group(s) edit       = arcpy.da.Editor(layer.workspacePath)                          # Need to make sure workspacePath is being populated  edit.startEditing(False, True) edit.startOperation()  # [...] cursor operations, data writing, updateRow calls here  edit.stopOperation() edit.stopEditing(True)

View solution in original post

3 Replies
NanaDei
Esri Contributor
Hi CCStormwater,
Can you please contact Esri Tech Support for further review on this behavior?

Thanks
0 Kudos
StormwaterWater_Resources
Regular Contributor
Just to close this out I'll reply to my own post.  I had been performing edits without initiating an edit session in the script.  Instead I started editing manually (Edit menu -> Start Editing), and then started the script.  This works without problems on an unversioned file GDB, but on a versioned SDE it fails.  The solution was to start the edit session within the script (and NOT start editing manually prior to starting the script).  See this Esri page for details:   Editor (arcpy.da) (Note: as of Apr 9, 2013 this page has a typo in example 2 at the bottom: the startEditing and startOperation call order is reversed, it should be startEditing first and then startOperation).

Some additional notes:  To run this from an active ArcMap session you need to get the edit layer's workspacePath.  For reasons I still don't understand if I change the version of a layer in the source tab of the Table of Contents the layer loses its workspacePath value.  Creating a database connection to your version of the SDE and loading layers from there seems to mitigate this issue (since you don't have to change the version).  Thus the pertinent code is as follows:

import arcpy, os  layerName  = arcpy.GetParameterAsText(0)                                   # Set script parameter as type Feature Layer mxd        = arcpy.mapping.MapDocument("CURRENT")                          # assuming one data frame layer      = arcpy.mapping.ListLayers(mxd, os.path.basename(layerName))[0] # basename strips off a ToC group(s) edit       = arcpy.da.Editor(layer.workspacePath)                          # Need to make sure workspacePath is being populated  edit.startEditing(False, True) edit.startOperation()  # [...] cursor operations, data writing, updateRow calls here  edit.stopOperation() edit.stopEditing(True)
StormwaterWater_Resources
Regular Contributor
See this Esri page for details:   Editor (arcpy.da) (Note: as of Apr 9, 2013 this page has a typo in example 2 at the bottom: the startEditing and startOperation call order is reversed, it should be startEditing first and then startOperation).


This typo has been corrected.
0 Kudos