Select to view content in your preferred language

KeyError when searching for assignments

1071
2
Jump to solution
05-27-2021 05:02 PM
DJOLeary
New Contributor

I am trying to fetch Assignments from the workforce app but when I attempt to perform this search:

 

    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() # <- This is the offending line
        print("Fetched assignments")

 

I get the following output and trace:

 

Signing into arcgis...
Signed in

Opening project...
Opened project Annual Inspections

Fetching assignments...
Traceback (most recent call last):
  File "newmain.py", line 6, in <module>
    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

 

 

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.

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

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.

View solution in original post

2 Replies
by Anonymous User
Not applicable

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.

RamonBatista
New Contributor

@DJOLeary @Anonymous User 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?

RamonBatista_0-1679918231621.png

 

0 Kudos