Opened 2 years ago

Last modified 2 years ago

#30516 closed Bug

raise_last_exception doesn't work with exception types with different __init__ signatures — at Version 1

Reported by: Alan Trick Owned by: nobody
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

Change History (1)

comment:1 Changed 2 years ago by Alan Trick

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top