[Django] #37408: ValueError shadows import errors

4 views
Skip to first unread message

Django

unread,
Oct 7, 2026, 11:39:42 AMOct 7
to django-...@googlegroups.com
#37408: ValueError shadows import errors
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Type:
| Cleanup/optimization
Status: new | Component: Tasks
Version: 6.1 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/37408>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 7, 2026, 11:41:38 AMOct 7
to django-...@googlegroups.com
#37408: ValueError shadows import errors
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Tasks | Version: 6.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Johannes Maron):

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.")
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37408#comment:1>

Django

unread,
Oct 7, 2026, 11:43:18 AMOct 7
to django-...@googlegroups.com
#37408: ValueError shadows import errors
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Tasks | Version: 6.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Johannes Maron):

BTW, the message suggests that we did a type-check, which don't :shrug:
--
Ticket URL: <https://code.djangoproject.com/ticket/37408#comment:2>
Reply all
Reply to author
Forward
0 new messages