#37002 closed Bug (duplicate)
Off-by-one error in parallel test worker index validation
| Reported by: | Shashank Kushwaha | Owned by: | |
|---|---|---|---|
| Component: | Testing framework | Version: | 6.0 |
| Severity: | Normal | Keywords: | parallel testing, off-by-one, worker-id |
| Cc: | Shashank Kushwaha | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (3)
comment:1 by , 97 minutes ago
comment:2 by , 71 minutes ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
It looks like this issue has been addressed in PR #20971 by adding validation for _worker_id >= len(db_aliases) before usage.
I’m marking this as fixed. Happy to close if no further action is needed.
i'd like to work on this , if accepted.