<?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 KeyError when searching for assignments in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/keyerror-when-searching-for-assignments/m-p/1062680#M6139</link>
    <description>&lt;P&gt;I am trying to fetch Assignments from the workforce app but when I attempt to perform this search:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    def run(self):
        gisAccount = GISAccount.SignIn()
        projectId = RecurringAssignmentHandler.ProjectId

        print("\nOpening project...")
        self.project = workforce.Project(gisAccount.content.get(projectId))
        print("Opened project " + self.project.title)

        print("\nFetching assignments...")
        allAssignments = self.project.assignments.search() # &amp;lt;- This is the offending line
        print("Fetched assignments")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following output and trace:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Signing into arcgis...
Signed in

Opening project...
Opened project Annual Inspections

Fetching assignments...
Traceback (most recent call last):
  File "newmain.py", line 6, in &amp;lt;module&amp;gt;
    raHandler.run()
  File "C:\Users\dev\Desktop\EsriProject\src\RecurringAssignments\RecurringAssignmentHandler.py", line 20, in run
    allAssignments = self.project.assignments.search()
  File "C:\Users\dev\Anaconda3\lib\site-packages\arcgis\apps\workforce\managers.py", line 67, in search
    return query_assignments(self.project, where)
  File "C:\Users\dev\Anaconda3\lib\site-packages\arcgis\apps\workforce\_store\assignments.py", line 48, in query_assignments
    assignments.append(workforce.Assignment(project, feature))
  File "C:\Users\dev\Anaconda3\lib\site-packages\arcgis\apps\workforce\assignment.py", line 136, in __init__
    self.assignment_type = self.project._cached_assignment_types[feature.attributes[project._assignment_schema.assignment_type]]
KeyError: 37&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any clue what is going on here? This code was running for months but has stopped running recently even though the code base was untouched. It has me completely stumped and I don't want to have to dive into the libraries code if I don't have to.&lt;/P&gt;</description>
    <pubDate>Fri, 28 May 2021 00:03:47 GMT</pubDate>
    <dc:creator>DJOLeary</dc:creator>
    <dc:date>2021-05-28T00:03:47Z</dc:date>
    <item>
      <title>KeyError when searching for assignments</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/keyerror-when-searching-for-assignments/m-p/1062680#M6139</link>
      <description>&lt;P&gt;I am trying to fetch Assignments from the workforce app but when I attempt to perform this search:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    def run(self):
        gisAccount = GISAccount.SignIn()
        projectId = RecurringAssignmentHandler.ProjectId

        print("\nOpening project...")
        self.project = workforce.Project(gisAccount.content.get(projectId))
        print("Opened project " + self.project.title)

        print("\nFetching assignments...")
        allAssignments = self.project.assignments.search() # &amp;lt;- This is the offending line
        print("Fetched assignments")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following output and trace:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Signing into arcgis...
Signed in

Opening project...
Opened project Annual Inspections

Fetching assignments...
Traceback (most recent call last):
  File "newmain.py", line 6, in &amp;lt;module&amp;gt;
    raHandler.run()
  File "C:\Users\dev\Desktop\EsriProject\src\RecurringAssignments\RecurringAssignmentHandler.py", line 20, in run
    allAssignments = self.project.assignments.search()
  File "C:\Users\dev\Anaconda3\lib\site-packages\arcgis\apps\workforce\managers.py", line 67, in search
    return query_assignments(self.project, where)
  File "C:\Users\dev\Anaconda3\lib\site-packages\arcgis\apps\workforce\_store\assignments.py", line 48, in query_assignments
    assignments.append(workforce.Assignment(project, feature))
  File "C:\Users\dev\Anaconda3\lib\site-packages\arcgis\apps\workforce\assignment.py", line 136, in __init__
    self.assignment_type = self.project._cached_assignment_types[feature.attributes[project._assignment_schema.assignment_type]]
KeyError: 37&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any clue what is going on here? This code was running for months but has stopped running recently even though the code base was untouched. It has me completely stumped and I don't want to have to dive into the libraries code if I don't have to.&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 00:03:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/keyerror-when-searching-for-assignments/m-p/1062680#M6139</guid>
      <dc:creator>DJOLeary</dc:creator>
      <dc:date>2021-05-28T00:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError when searching for assignments</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/keyerror-when-searching-for-assignments/m-p/1062695#M6140</link>
      <description>&lt;P&gt;I think you may have an assignment in the project that references an assignment type that no longer exists. I think the code is looking up the assignment type and there's no assignment type code for 37.&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 01:20:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/keyerror-when-searching-for-assignments/m-p/1062695#M6140</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-05-28T01:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError when searching for assignments</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/keyerror-when-searching-for-assignments/m-p/1271860#M8552</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/488308"&gt;@DJOLeary&lt;/a&gt;&amp;nbsp;@Anonymous User&amp;nbsp;Hello, I'm seeing the same error with the script, but instead of KeyError 37 is KeyError 9, could you show how you fixed this error?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RamonBatista_0-1679918231621.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/66320i5E2315A2920070CA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RamonBatista_0-1679918231621.png" alt="RamonBatista_0-1679918231621.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 11:57:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/keyerror-when-searching-for-assignments/m-p/1271860#M8552</guid>
      <dc:creator>RamonBatista</dc:creator>
      <dc:date>2023-03-27T11:57:24Z</dc:date>
    </item>
  </channel>
</rss>

