Bulk user import and export crash on malformed CSVs and bad options instead of reporting an error
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Target branch: develop
Observed behavior
- Web: selecting an empty CSV in Facility > Data > Import and clicking Continue shows nothing. The server rejects the upload with a 400 that nothing in the frontend handles.
- CLI:
kolibri manage bulkimportuserson an empty file crashes incsv_headers_validation. bulkimportusersandbulkexportusersalso raise an uncaught exception on each input in the table below. In Facility > Data > Import, a failed task with nooverall_errorgoes tohandleApiErrorwith its traceback (actions.js#L61-L63) instead of the import's error list.
https://github.com/user-attachments/assets/b092da9b-a9ea-478a-9219-b7a8712fac9a
Errors and logs
CLI:
File "kolibri/core/auth/management/commands/bulkimportusers.py", line 497, in csv_headers_validation
header = next(csv.reader(f, strict=True))
StopIteration
| Input | Exception | Raised at |
|---|---|---|
Header with an unclosed quote: "UUID,USERNAME |
_csv.Error: unexpected end of data |
bulk_import.py#L466 |
Row with no USERNAME cell |
AttributeError: 'NoneType' object has no attribute 'lower' |
bulk_import.py#L273 |
Row missing later cells, e.g. ,bob,pass,Bob |
IndexError: Replacement index 1 out of range |
bulk_import.py#L350 |
Unknown or malformed --facility, import |
Facility.DoesNotExist / ValueError |
bulk_import.py#L695 |
Unknown or malformed --facility, export |
Facility.DoesNotExist / ValueError |
bulk_export.py#L230 |
--errorlines <path> from the CLI |
AttributeError: 'str' object has no attribute 'write' |
bulk_import.py#L840 |
Malformed --userid with --delete, import |
ValueError: badly formed hexadecimal UUID string |
bulk_import.py#L716-L726 |
Steps to reproduce
- Create an empty
empty.csv. - As a facility admin, open Facility > Data, click Import, select
empty.csv, click Continue. - On a device with a facility, run
kolibri manage bulkimportusers empty.csv. - Run
kolibri manage bulkimportusers <file> --facility <facility id>with each CSV in the table. - Run
kolibri manage bulkimportusers <valid file> --facility <id>andkolibri manage bulkexportusers --facility <id>with an unknown hex ID, then withnotauuid. - Run
kolibri manage bulkimportusers <file with an unknown UUID row> --facility <facility id> --errorlines errors.txt. - Run
kolibri manage bulkimportusers <valid file> --facility <facility id> --delete --userid notauuid.
Acceptance Criteria
- [ ] Selecting an empty file in the import file input shows an inline error under the input saying the file is empty; Continue stays disabled.
- [ ] Selecting a non-empty file afterwards clears the error and enables Continue.
- [ ]
kolibri manage bulkimportuserson an empty file raisesCommandErrorwith an untranslated English message saying the file is empty. - [ ] A Jest spec covers the empty-file error in
Init.vue; a pytest test covers theCommandError. - [ ] A CSV whose header row the CSV reader rejects stops the import with a file error, printed in the CLI's
CommandErrorand listed in Facility > Data > Import under "Importing is not possible due to the following errors:". - [ ] A row with no
USERNAMEcell, or missing any later cell, is reported as an error on that row; the file's valid rows import. - [ ] An unknown or malformed
--facilitymakesbulkimportusersandbulkexportusersexit with aCommandError. - [ ]
bulkimportusers --errorlines <path>writes each row error to<path>. - [ ]
bulkimportusers --userid notauuid, with and without--delete, exits with aCommandErrornaming the value and changes no user or class; a pytest test covers both. - [ ] These repro tests from #15792 pass:
test_empty_csv_reports_error,test_unparseable_header_reports_error,test_row_without_username_cell_reports_row_error,test_row_without_user_type_cell_reports_row_error,test_unknown_facility_import_reports_error,test_malformed_facility_import_reports_error,test_unknown_facility_export_reports_error,test_malformed_facility_export_reports_error,test_errorlines_path_from_cli.
AI usage
@rtibbles chose the frontend check and the untranslated CLI error; Claude Code reproduced the CLI crash and drafted this revision.
Hi! I’m a CS major at the University of Michigan taking a software engineering course, where one of our assignments is to contribute to an opens source project. I want to contribute to Kolibri for the next week or so. I’d love to work on this issue (and potentially another one) for my assignment. Would appreciate any advice or confirmation that no one else is actively working on this. Thanks!
Hi @amyjun26. This issue is not available. You're welcome to find an unassigned 'help wanted' issue instead. There aren't many available issues right now so it's best to wait and keep an eye on the list. We label new ones on a weekly basis. I'd also invite you to have a look at the contributing guidelines (CONTRIBUTING.md) if you haven't seen them yet. Thank you.
The empty file is one of several inputs bulkimportusers and bulkexportusers crash on instead of reporting an error. From #15792; added to the body.
| Input | Exception | Raised at |
|---|---|---|
Header with an unclosed quote: "UUID,USERNAME |
_csv.Error: unexpected end of data |
bulk_import.py#L466 |
Row with no USERNAME cell |
AttributeError: 'NoneType' object has no attribute 'lower' |
bulk_import.py#L273 |
Row missing later cells, e.g. ,bob,pass,Bob |
IndexError: Replacement index 1 out of range |
bulk_import.py#L350 |
Unknown or malformed --facility, import |
Facility.DoesNotExist / ValueError |
bulk_import.py#L695 |
Unknown or malformed --facility, export |
Facility.DoesNotExist / ValueError |
bulk_export.py#L230 |
--errorlines <path> from the CLI |
AttributeError: 'str' object has no attribute 'write' |
bulk_import.py#L840 |
- In Facility > Data > Import, a failed task with no
overall_errorreacheshandleApiErrorwith its traceback (actions.js#L61-L63), not the import's error list. append_error/exit_if_erroralready carry a file error to the CLI'sCommandErrorand toPreview.vue;Validator.validateyields the row-error shape.- Repro tests, in #15792's Testing Requirements:
test_empty_csv_reports_error,test_unparseable_header_reports_error,test_row_without_username_cell_reports_row_error,test_row_without_user_type_cell_reports_row_error,test_unknown_facility_import_reports_error,test_malformed_facility_import_reports_error,test_unknown_facility_export_reports_error,test_malformed_facility_export_reports_error,test_errorlines_path_from_cli. Theirfieldnamesimport now lives inkolibri/core/auth/utils/bulk_import.py.
Written by rtibblesbot, an LLM-based coding agent.
Plan: Issue #13260. Every input in the issue's table, plus an empty file, turns into a reported error (inline in the UI, a file error, a row error, or a CommandError) instead of an uncaught exception.
- [ ] Inline empty-file error on the import page
- [ ] Empty and unparseable files become file errors
- [ ] Rows with missing cells become row errors
- [ ] Unknown or malformed
--facilityexits withCommandError - [ ]
--errorlines <path>from the CLI - [ ] Self-review the produced code
Assumptions — the issue did not settle these; say so if one is wrong.
- Missing-cell row error reuses
REQUIRED_COLUMN("The column '{}' is required"), one per missing cell; if wrong, a new translatableMESSAGESentry is added. - A row missing only optional trailing cells (e.g.
ENROLLED_IN) is an error, per "missing any later cell"; if wrong, such rows import with blanks viarestval="". Open PR #15800'stest_row_shorter_than_header_creates_userasserts the opposite for a missing trailingUUID; a reply draft on #15800 flags it. - Empty-file error goes through
exit_if_error, so the CLI printsFile errors: ['<message>']; if a bare message is wanted, raiseBulkUserImportErrordirectly. get_facilitycatching malformed ids also turnsregisterfacility/deletefacility/recreatefacility/sync crashes intoCommandError; if unwanted, catch in the bulk managers only.Init.vuestays Options API with a new$trsentry; if asetup()conversion is wanted, the strings move tocreateTranslatorand their ids change.- Clearing the file picker clears the empty-file error; if it should persist,
filesChangedresets the flag only on a non-empty pick.
Written by rtibblesbot, an LLM-based coding agent.
Another bad option bulkimportusers crashes on; added to the body.
| Input | Exception | Raised at |
|---|---|---|
Malformed --userid with --delete |
ValueError: badly formed hexadecimal UUID string |
bulk_import.py#L716-L726 |
- Repro:
kolibri manage bulkimportusers <valid file> --facility <facility id> --delete --userid notauuid. - With #15926 applied, the same
--useridraises without--deletetoo, fromBulkUserImportManager.__init__. - New criterion:
--userid notauuid, with and without--delete, exits with aCommandErrornaming the value and changes no user or class; a pytest test covers both.
Written by rtibblesbot, an LLM-based coding agent.
rtibbles Self-review did not converge on this branch, so nothing was pushed, and any replies to this round wait for the push. Open findings:
- suggestion
kolibri/core/auth/test/test_bulk_input_errors.py:116::116,:142and:152patch the first-partyFacility.get_default_facilityso a fallback to the default facility would surface. Callprovision_device()from `kolibri/core/auth/test/helpers.py:4 - blocking
kolibri/core/auth/utils/bulk_import.py:782: One row with blankUUIDandUSERNAMEturns off--deletefor the whole import, and nothing reports it. Spreadsheets often export trailing rows that are only commas, so this will happen in practic - suggestion
kolibri/core/auth/utils/bulk_import.py:76: Most of the uncommittedbulk_import.pyrewrite belongs to sibling issues, not #13260. Move it to the PRs for those issues:
Reply just push to push this tree as it is, or reply with direction and another review round runs.
Written by rtibblesbot, an LLM-based coding agent.
These all sound like important fixes - carry on.
@rtibbles Blocked — these cannot be assumed either way:
- A deleted facility leaves a queued web export stuck in Exporting. The fix would record the lookup error on the job and have the web poller display it and reset the export state; #13260 names only CLI export. Fix it here, file a follow-up issue, or leave it?
Written by rtibblesbot, an LLM-based coding agent.
Fix it here.
@rtibbles Blocked — these cannot be assumed either way:
- A retry POST returning 400 leaves an existing CSV unavailable. The fix preserves the pending file lookup until the retry queues; consult 4 explicitly leaves this race open. Fix it here, file a follow-up issue, or leave it?
Written by rtibblesbot, an LLM-based coding agent.
Fix it here.
@rtibbles Blocked — these cannot be assumed either way:
- A second tab can clear a failed export before the initiating tab sees it. The fix would leave failed jobs in the task list, as develop does; consult 5 explicitly requires clearing them. Fix it here, file a follow-up issue, or leave it?
Written by rtibblesbot, an LLM-based coding agent.
Leave it - multitab behaviour is always going to give edge cases.
@rtibbles Self-review did not converge on this branch, so nothing was pushed, and any replies to this round wait for the push. Open findings:
- suggestion
kolibri/plugins/facility/frontend/modules/manageCSV/actions.js:117: The missing-task reconciliation handles only a tracked export that something else cleared, which in practice means another tab. That covers this block,requestedId, theusersOnlylookup, `exportUs - suggestion
kolibri/plugins/facility/frontend/views/DataPage/__tests__/DataPage.spec.js:534: All 22 tests still pass after either of two changes: replace the task-id check atactions.js:92withtrue, or reduceindex.js:150toif (state.exportUsersTaskId). This test's "before the expor - suggestion
kolibri/plugins/facility/frontend/views/DataPage/index.vue:305: The facility-list callback starts polling even after the component is destroyed.
Reply just push to push this tree as it is, or reply with direction and another review round runs.
Written by rtibblesbot, an LLM-based coding agent.
Decided without asking; a reply here changes it.
- Pushing the tree as it is. All three open self-review findings are suggestions, and the tree passes the facility Jest specs (152), the bulk import/export pytest files (121) and
prekon the changed files. "Carry on" (2026-11-19) answered a round with a blocking finding; this round has none.- Missing-task handling in
manageCSV(acts only when another tab clears the tracked export): kept. "Leave it" (2026-11-22) rules out another round on multi-tab behaviour, to remove code as much as to add it. It is already written, small beside the branch, and returns the tab to idle once a user CSV exists, where develop leaves it in Exporting. Removal can be asked for on the PR. - Guards at
manageCSV/actions.js:92andindex.js:150that no spec exercises: they act only in that same multi-tab state, so no test is added. - Task polling that keeps running when the Data page is left before the facility list loads:
upstream/developdoes the same, and the fix is outside this issue. Not fixed here.
- Missing-task handling in
Written by rtibblesbot, an LLM-based coding agent.
Decided without asking; a reply here changes it.
All three concern changing the facility while Facility > Data stays open. That happens only when the facility id in the URL is edited by hand: Change learning facility goes through the facility list and reopens the page (checked live in QA). A Jest probe of develop, the branch and the branch without its reload-on-facility-change (.plans/advice2_probe) shows develop refetches nothing after such an edit: the new facility stays on "Generating CSV..." and Generate sends no request. The branch's reload fixes that and stays; it is written, small, and on the export state this issue reworks.
- Stale export error and lost export after a URL-edit switch: left as it is. Now broken: until the facility list returns, the new facility shows the previous facility's export error, and an export queued in that window that then fails is not reported. The branch's reload causes both, which argues for fixing here; no user is known to reach them, and the fix adds facility-keyed export state the issue does not need, so the edge-case line wins. Opening the page has the same window, already left as develop has it.
- Usage-log dates: follow-up issue queued, no change here. Clicking Generate log before the first log date loads raises
TypeError: Cannot read properties of null (reading 'getDate')and the date dialog never opens, on develop at every page open; the branch adds the same window after a URL-edit switch. Disabling the usage-log buttons until the date loads is a new mechanism in a feature this branch does not touch. A late date response from the previous facility replacing the new one's is left: develop always keeps the previous facility's date there. - Facility-list reloads after a URL-edit switch: left as they are. Now broken: a failed facility-list request rejects unhandled and keeps the previous facility's state, and repeated switches repeat the metadata requests. Develop keeps the previous facility's state on every such switch and rejects unhandled the same way when the page opens. Edge case with no known affected user; deduplication and a separate refresh path are remedies nobody asked for.
Written by rtibblesbot, an LLM-based coding agent.