<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Workspace already in transaction mode — two separate edit sessions in ArcMap Questions</title>
    <link>https://community.esri.com/t5/arcmap-questions/workspace-already-in-transaction-mode-two-separate/m-p/1183084#M3846</link>
    <description>&lt;P&gt;Turns out that while the tiles feature class was set to versioned, the related table was not. Changing the related table to versioned fixed the error. Still would have been nice to have an error message that might have pointed toward this being the problem...&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jun 2022 12:18:23 GMT</pubDate>
    <dc:creator>IanTodd</dc:creator>
    <dc:date>2022-06-15T12:18:23Z</dc:date>
    <item>
      <title>Workspace already in transaction mode — two separate edit sessions</title>
      <link>https://community.esri.com/t5/arcmap-questions/workspace-already-in-transaction-mode-two-separate/m-p/1182896#M3843</link>
      <description>&lt;P&gt;I'm creating an ArcMap toolbar that will be used to update a feature layer and related table in an SDE. As of now, I'm creating two edit sessions: one for the layer and one for the table — preferably, I could do it in one edit session. However, I get an error that the workspace is already in transaction when I try to insert a row into the related table.&lt;/P&gt;&lt;P&gt;The onClick method kicks off the attempt. It successfully runs the first start method (in Tiles), but fails with a transaction mode error for the second start method (in RelatedTable).&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def editor(sub_function):
    def _runner(*args, **kwargs):
        edit = arcpy.da.Editor(Tiles.root())
        result = None
        try:
            edit.startEditing(False, True)
            edit.startOperation()
            result = sub_function(*args, **kwargs)
            success = True
        except Exception as e:
            print(traceback.format_exc())
            success = False
        finally:
            if edit.isEditing:
                edit.stopOperation()
                edit.stopEditing(success)
            del edit
            return result
    return _runner&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;    def onClick(self):
        result, tile_id, row = Tiles.start()
        if result == Tiles.NO_ERROR:
            result = RelatedTable.start(tile_id)
            if result:
                KeyMaster.tile_start()
            else:
                Tiles.revert_start(row)
        elif result == Tiles.SELECTION_COUNT_INVALID:
            send_message("Only one tile can be selected.", 'Error')
        elif result == Tiles.SELECTION_VALUE_INVALID:
            send_message('The tile must be "checked out" in your name before it can be started.', 'Error')&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;    @classmethod
    def start(cls):
        @editor
        def updater():
            fields = [EditFields.user, EditFields.status, FieldNames.id]
            tile_id, row = None, None
            with arcpy.da.UpdateCursor(Tiles.get(), fields) as cursor:
                for row in cursor:
                    if (row[0] == FieldValues.USERNAME) or KeyMaster.is_unlocked():
                        row[0] = FieldValues.USERNAME
                        row[1] = FieldValues.STARTED
                        tile_id = row[2]
                        cursor.updateRow(row)
            return tile_id, row

        fids = cls.fid_set()
        if len(fids) != 1:
            return Tiles.SELECTION_COUNT_INVALID, None, None
        tile_id, row = updater()
        if tile_id is not None:
            return Tiles.NO_ERROR, tile_id, row
        else:
            return Tiles.SELECTION_VALUE_INVALID, None, None&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;    @classmethod
    def start(cls, tile_id):
        @editor
        def updater():
            fields = [RelatedTable._userField,
                    RelatedTable._startField,
                    RelatedTable._idField,
                    RelatedTable._typeField]
            with arcpy.da.InsertCursor(RelatedTable.get(), fields) as cursor:
                row = [FieldValues.USERNAME,
                        datetime.datetime.now(),
                        tile_id,
                        EditFields.get_type()]
                RelatedTable.set_fid(cursor.insertRow(row))
                RelatedTable.set_id(tile_id)
            return True
        success = updater()
        if success:
            return Tiles.NO_ERROR
        else:
            return Tiles.SELECTION_COUNT_INVALID&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 14 Jun 2022 20:05:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/workspace-already-in-transaction-mode-two-separate/m-p/1182896#M3843</guid>
      <dc:creator>IanTodd</dc:creator>
      <dc:date>2022-06-14T20:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace already in transaction mode — two separate edit sessions</title>
      <link>https://community.esri.com/t5/arcmap-questions/workspace-already-in-transaction-mode-two-separate/m-p/1182945#M3844</link>
      <description>&lt;P&gt;I suspect it is because you are trying to loop through an insertCursor.&amp;nbsp; Just set the cursor to a variable, then insertRow(value).&lt;/P&gt;&lt;P&gt;This &lt;A href="https://support.esri.com/en/technical-article/000019111" target="_self"&gt;tech support&lt;/A&gt; article and this &lt;A href="https://community.esri.com/t5/python-questions/workspace-already-in-transaction-mode-two-cursors/td-p/207626" target="_self"&gt;post&lt;/A&gt; should give you good enough example to see if that is the issue.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 23:18:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/workspace-already-in-transaction-mode-two-separate/m-p/1182945#M3844</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-06-14T23:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace already in transaction mode — two separate edit sessions</title>
      <link>https://community.esri.com/t5/arcmap-questions/workspace-already-in-transaction-mode-two-separate/m-p/1183075#M3845</link>
      <description>&lt;P&gt;InsertCursor is not being used in a loop. As the code's written, the InsertCursor is called in a completely different function well after UpdateCursor has fallen out of scope. I did try setting InsertCursor as a variable, but I'm getting the same problem.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 11:21:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/workspace-already-in-transaction-mode-two-separate/m-p/1183075#M3845</guid>
      <dc:creator>IanTodd</dc:creator>
      <dc:date>2022-06-15T11:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Workspace already in transaction mode — two separate edit sessions</title>
      <link>https://community.esri.com/t5/arcmap-questions/workspace-already-in-transaction-mode-two-separate/m-p/1183084#M3846</link>
      <description>&lt;P&gt;Turns out that while the tiles feature class was set to versioned, the related table was not. Changing the related table to versioned fixed the error. Still would have been nice to have an error message that might have pointed toward this being the problem...&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 12:18:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/workspace-already-in-transaction-mode-two-separate/m-p/1183084#M3846</guid>
      <dc:creator>IanTodd</dc:creator>
      <dc:date>2022-06-15T12:18:23Z</dc:date>
    </item>
  </channel>
</rss>

