Opened 3 weeks ago

Last modified 3 weeks ago

#37408 assigned Cleanup/optimization

Add a custom error for task not found errors

Reported by: Johannes Maron Owned by: Johannes Maron
Component: Tasks Version: 6.1
Severity: Normal Keywords:
Cc: Johannes Maron, Jake Howard Triage Stage: Accepted
Has patch: yes 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 (6)

comment:1 by Johannes Maron, 3 weeks ago

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.")

comment:2 by Johannes Maron, 3 weeks ago

BTW, the message suggests that we did a type-check, which don't :shrug:

comment:3 by Sarah Boyce, 3 weeks ago

Cc: Jake Howard added
Summary: ValueError shadows import errors → Add a custom error for task not found errors
Triage Stage: Unreviewed → Accepted

I think a custom error is reasonable. Needs docs similar to TaskError (and a versionadded note etc)

comment:4 by Jake Howard, 3 weeks ago

I'd suggest naming it TaskDoesNotExist to mirror the existing TaskResultDoesNotExist, and match the similar ORM exceptions. There's already InvalidTask, but this feels sufficiently different to warrant its own exception.

comment:5 by Johannes Maron, 3 weeks ago

Owner: set to Johannes Maron
Status: new → assigned

TaskDoesNotExist sounds great, I'll whip up a small patch.

comment:6 by Johannes Maron, 3 weeks ago

Has patch: set
Note: See TracTickets for help on using tickets.
Back to Top