#37002: Off-by-one error in parallel test worker index validation
-------------------------------------+-------------------------------------
Reporter: Shashank Kushwaha | Type: Bug
Status: new | Component: Testing
| framework
Version: 6.0 | Severity: Normal
Keywords: parallel testing, | Triage Stage:
off-by-one, worker-id | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
In django/test/runner.py, the validation of _worker_id uses:
if _worker_id > len(db_aliases):
However, valid worker IDs should range from 0 to len(db_aliases) - 1.
For example, if len(db_aliases) = 3, valid IDs are 0, 1, and 2. The
current condition allows _worker_id == 3, which is invalid.
This appears to be an off-by-one error and should likely use:
if _worker_id >= len(db_aliases):
This was observed while reviewing PR #20971.
--
Ticket URL: <
https://code.djangoproject.com/ticket/37002>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.