Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30516 closed Bug (fixed)

Autoreloader crashes on re-raising exceptions with custom signature.

Reported by: Alan Trick Owned by: Tom Forbes
Component: Utilities Version: 2.2
Severity: Release blocker Keywords: autoreload
Cc: Tom Forbes Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alan Trick)

How to reproduce:

In apps.py, put the following code, and update init.py or the settings to have this app config be used.

from django.apps import AppConfig

class MyException(Exception):
    def __init__(self, value: str, other_thing: str):
        super().__init__(value)
        self.ot = other_thing

class Config(AppConfig):
    name = "myapp"
    verbose_name = "My App"

    def ready(self):
        raise MyException("foo", "bar")

The problem is that django.utils.autoreload.raise_last_exception tries to construct a new exception of the same type, with 1 argument (the original exception). The consequence is that you just get a TypeError exception about __init__() missing 1 required positional argument: 'other_thing' and it completely masks the original exception.

Note that this behavior was changed in c8720e7696ca41f3262d5369365cc1bd72a216ca, it used to just re-raise the exception value. I don't know why it was changed.

I noticed this issue as a result of https://gitlab.com/alantrick/django-vox/issues/9

Attachments (1)

30516.diff (1.1 KB ) - added by Mariusz Felisiak 5 years ago.
Regression test.

Download all attachments as: .zip

Change History (6)

comment:1 by Alan Trick, 5 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 5 years ago

Cc: Tom Forbes added
Component: UncategorizedUtilities
Keywords: autoreload added
Severity: NormalRelease blocker
Summary: raise_last_exception doesn't work with exception types with different __init__ signaturesAutoreloader crashes on re-raising exceptions with custom signature.
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Thanks for the report.

Regression in c8720e7696ca41f3262d5369365cc1bd72a216ca.
Reproduced at df46b329e0900e9e4dc1d60816c1dce6dfc1094e.

by Mariusz Felisiak, 5 years ago

Attachment: 30516.diff added

Regression test.

comment:3 by Tom Forbes, 5 years ago

Has patch: set
Owner: changed from nobody to Tom Forbes
Status: newassigned

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 0344565:

Fixed #30516 -- Fixed crash of autoreloader when re-raising exceptions with custom signature.

Regression in c8720e7696ca41f3262d5369365cc1bd72a216ca.

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In ace0bec8:

[2.2.x] Fixed #30516 -- Fixed crash of autoreloader when re-raising exceptions with custom signature.

Regression in c8720e7696ca41f3262d5369365cc1bd72a216ca.

Backport of 0344565179527d80990e2247e3be7c04aa8c43c8 from master

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