Opened 49 minutes ago
Last modified 46 minutes ago
#37408 new Cleanup/optimization
ValueError shadows import errors
| Reported by: | Johannes Maron | Owned by: | |
|---|---|---|---|
| Component: | Tasks | Version: | 6.1 |
| Severity: | Normal | Keywords: | |
| Cc: | Johannes Maron | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
Regression from #36919
When a user renames or moves a task, deconstruction fails with an ambiguous ValueError shadowing the ImportError.
https://github.com/django/django/blob/cf564bf3a7e0d92bc32292ccff1eca5aeb24b1ef/django/tasks/base.py#L64-L66
shadows ImportError.
Currently you'd need to access causes to figure out that the ValueError was actually because the tasks can't be found.
It would be more suitable to fail with a custom error, which backends catch and handle more gracefully.
Change History (2)
comment:1 by , 47 minutes ago
comment:2 by , 46 minutes ago
BTW, the message suggests that we did a type-check, which don't :shrug:
I would propose something like:
class TaskNotFoundException(ValueError): def __init__(self, func_path, *args, **kwargs): self.func_path = func_path super().__init__(f"Expected {func_path!r} to point to a Task instance.")