Skip to content

Validating a data set containing a field with an invalid pick list assigned results in an IndexError('list index out of range') #7375

@grantfitzsimmons

Description

@grantfitzsimmons

Describe the bug
When validating a data set with a field assigned to an invalid pick list, the user sees the following error: IndexError: list index out of range

To Reproduce
Steps to reproduce the behavior:

  1. Set a field in the Schema Config to point to an invalid pick list (create a pick list, assign it to a field, then remove it from query builder search results)
  2. Map that field in the WorkBench
  3. Validate the data set
  4. See error

Expected behavior
It should treat the field as if no pick list is assigned (no crash, no list item validation for cells).

Screenshots
Most recent incident of this:
Image

Crash Report

{
  "uploaderstatus": {
    "operation": "validating",
    "taskid": "d93bc594-2d7d-4d34-ac11-9ee55cac75be"
  },
  "taskstatus": "FAILURE",
  "taskinfo": "IndexError('list index out of range')"
}

From the worker logs directly (a truncated version of this is shown to the user):

[2025-08-28 15:21:32,342: ERROR/ForkPoolWorker-1] Task specifyweb.workbench.tasks.upload[da31eaae-a9ea-4e1b-879d-1ed9deb7ae2f] raised unexpected: IndexError('list index out of range')
Traceback (most recent call last):
  File "/opt/specify7/ve/lib/python3.12/site-packages/celery/app/trace.py", line 453, in trace_task
    R = retval = fun(*args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^
  File "/opt/specify7/ve/lib/python3.12/site-packages/celery/app/trace.py", line 736, in __protected_call__
    return self.run(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/specify7/specifyweb/workbench/tasks.py", line 57, in upload
    upload_data(collection_id, uploading_agent_id, ds_id, no_commit, allow_partial, self, progress)
  File "/opt/specify7/specifyweb/workbench/tasks.py", line 45, in upload_data
    do_upload_dataset(collection, uploading_agent_id, ds, no_commit, allow_partial, progress)
  File "/opt/specify7/specifyweb/workbench/upload/upload.py", line 185, in do_upload_dataset
    results = do_upload(
              ^^^^^^^^^^
  File "/opt/specify7/specifyweb/workbench/upload/upload.py", line 340, in do_upload
    scoped_table = upload_plan.apply_scoping(collection, scope_context, row)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/specify7/specifyweb/workbench/upload/upload_table.py", line 75, in apply_scoping
    return apply_scoping_to_uploadtable(self, collection, context, row)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/specify7/specifyweb/workbench/upload/scoping.py", line 299, in apply_scoping_to_uploadtable
    f: extend_columnoptions(colopts, collection, table.name, f, row, ut.toOne, context)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/specify7/specifyweb/workbench/upload/scoping.py", line 122, in extend_columnoptions
    picklist = None if picklists is None else picklists[0]
                                              ~~~~~~~~~^^^
  File "/opt/specify7/ve/lib/python3.12/site-packages/django/db/models/query.py", line 450, in __getitem__
    return qs._result_cache[0]
           ~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

Reported By
Reported by Kamil Dobosz on behalf of MCSN (Lugano)


Workaround

You need to find all items in the splocalecontaineritem table where the PickListName does not exist in the ⁠picklist table in the ⁠Name column

You can find all pick list items that will cause this case by running the following:

SELECT
    d.Name                   AS `Discipline`,
    sc.Name                  AS `Table`,
    slc.Name                 AS `Column`,
    slc.SpLocaleContainerItemID,
    slc.PickListName,
    p.TableName              AS `PickList Table`,
    sps.Text                 AS `Field Label`,
    slc.IsHidden             AS `Is Hidden?`,
    sps.Language             AS `Language`,
    sps.Country              AS `Country`
FROM splocaleitemstr AS sps
JOIN splocalecontaineritem AS slc
  ON sps.SpLocaleContainerItemNameID = slc.SpLocaleContainerItemID
JOIN splocalecontainer AS sc
  ON slc.SpLocaleContainerID = sc.SpLocaleContainerID
JOIN discipline AS d
  ON sc.DisciplineID = d.UserGroupScopeId
LEFT JOIN picklist AS p
  ON slc.PickListName = p.Name
WHERE slc.PickListName IS NOT NULL
  AND p.Name IS NULL;

In the results, you'll see this:

Discipline Table Column PickListName PickList Table Field Label Is Hidden? Language Country
Paleobotany collectionobject text1 Phenology Phenology 1 en

You can fix this either in the Schema Config directly or by removing the PickListName value from the splocalecontaineritem record directly in the database.

Metadata

Metadata

Assignees

No one assigned

    Labels

    2 - WorkBenchIssues that are related to the WorkBench

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions