Description
esp/esp/program/modules/handlers/lineitemsmodule.py uses direct .objects.get(...) calls on request-supplied IDs in several edit/delete/import paths without graceful handling for invalid or stale IDs.
Why this matters
LineItemsModule is an admin-facing accounting/configuration workflow. If an item has been deleted, an ID is stale, or the request is tampered with, the module should show a recoverable error rather than crashing.
Current flows include patterns such as:
LineItemType.objects.get(id=request.GET['id'])
LineItemType.objects.get(id=request.POST['id'])
Program.objects.get(id=request.POST['program'])
with no surrounding DoesNotExist or parsing guards.
Evidence
Relevant code in esp/esp/program/modules/handlers/lineitemsmodule.py:
- edit flow:
LineItemType.objects.get(id=request.GET['id'])
- delete confirmation:
LineItemType.objects.get(id=request.GET['id'])
- confirmed deletion:
LineItemType.objects.get(id=request.POST['id'])
- import confirmation:
Program.objects.get(id=request.POST['program'])
These request-derived lookups are performed directly with no defensive handling.
Steps to Reproduce
- Open the Line Items management UI.
- Trigger an edit, delete, or import path using an invalid, deleted, or tampered ID in the request.
- Observe that the handler performs direct
.objects.get(...) lookups from request parameters.
- If the referenced object does not exist, the flow can raise an unhandled exception.
Expected Behavior
The module should detect invalid IDs and return a clear admin-facing error, without crashing the entire page.
Actual Behavior
Stale or invalid IDs can lead to DoesNotExist exceptions and 500 responses.
Suggested Fix
Wrap request-derived object lookups in validation and exception handling:
- catch
LineItemType.DoesNotExist
- catch
Program.DoesNotExist
- catch
ValueError where IDs are parsed
- return a clean
ESPError instead of a raw exception
Additional Context
I checked the current issue tracker with searches around lineitemsmodule, LineItemType.objects.get, and line-item edit/delete crashes. I only found the test-coverage issue #5210, not an existing bug issue for this invalid-ID crash path.
Description
esp/esp/program/modules/handlers/lineitemsmodule.pyuses direct.objects.get(...)calls on request-supplied IDs in several edit/delete/import paths without graceful handling for invalid or stale IDs.Why this matters
LineItemsModuleis an admin-facing accounting/configuration workflow. If an item has been deleted, an ID is stale, or the request is tampered with, the module should show a recoverable error rather than crashing.Current flows include patterns such as:
LineItemType.objects.get(id=request.GET['id'])LineItemType.objects.get(id=request.POST['id'])Program.objects.get(id=request.POST['program'])with no surrounding
DoesNotExistor parsing guards.Evidence
Relevant code in
esp/esp/program/modules/handlers/lineitemsmodule.py:LineItemType.objects.get(id=request.GET['id'])LineItemType.objects.get(id=request.GET['id'])LineItemType.objects.get(id=request.POST['id'])Program.objects.get(id=request.POST['program'])These request-derived lookups are performed directly with no defensive handling.
Steps to Reproduce
.objects.get(...)lookups from request parameters.Expected Behavior
The module should detect invalid IDs and return a clear admin-facing error, without crashing the entire page.
Actual Behavior
Stale or invalid IDs can lead to
DoesNotExistexceptions and 500 responses.Suggested Fix
Wrap request-derived object lookups in validation and exception handling:
LineItemType.DoesNotExistProgram.DoesNotExistValueErrorwhere IDs are parsedESPErrorinstead of a raw exceptionAdditional Context
I checked the current issue tracker with searches around
lineitemsmodule,LineItemType.objects.get, and line-item edit/delete crashes. I only found the test-coverage issue#5210, not an existing bug issue for this invalid-ID crash path.