#30516: raise_last_exception doesn't work with exception types with different
__init__ signatures
-------------------------------+--------------------------------------
     Reporter:  alantrick      |                    Owner:  nobody
         Type:  Uncategorized  |                   Status:  new
    Component:  Uncategorized  |                  Version:  2.2
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Description changed by alantrick:

Old description:

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

New description:

 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

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30516#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.8180ec8d5dea2a522c5f452c2c3afa0f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to