Setting the `app_label` of an `AppConfig` object is allowed and fails
later on during migrations (`./manage.py migrate`) with `(too many values
to unpack)`.
It took me a couple of minutes to figure out what was wrong, but it may
not be so obvious to an inexperienced user so it may be better to raise a
clearer exception.
Maybe we can use system checks and fail earlier if such a problem is
detected?
--
Ticket URL: <https://code.djangoproject.com/ticket/32285>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => needsinfo
* type: Bug => Cleanup/optimization
* component: Core (System checks) => Core (Other)
Comment:
Raising `ImproperlyConfigured` should be enough, however everything works
for me with dotted label, e.g. `ticket_32285.test_one`. Can you provide a
sample project?
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:1>
* status: closed => new
* resolution: needsinfo =>
* stage: Unreviewed => Accepted
Comment:
It looks that it will be good to raise an error to avoid confusions (see
#32287), even if I cannot reproduce this crash.
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:2>
* owner: nobody => Hasan Ramezani
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:3>
Comment (by Federico Capoano):
Have you already tried to create a new django app, put a dot in the
app_label field of the AppConfig, ensure the AppConfig is mentioned in the
__init__.py, then create a model and run ./manage.py makemigrations?
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:4>
Comment (by Mariusz Felisiak):
Replying to [comment:4 Federico Capoano]:
> Have you already tried to create a new django app, put a dot in the
app_label field of the AppConfig, ensure the AppConfig is mentioned in the
__init__.py, then create a model and run ./manage.py makemigrations?
Yes. Can you share a stacktrace? I'm not even sure in which line or file
you encountered this issue 🤔
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:5>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/13796 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:6>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:7>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"8b2a30f6f16cb1f3538847954030d69da005bc7f" 8b2a30f]:
{{{
#!CommitTicketReference repository=""
revision="8b2a30f6f16cb1f3538847954030d69da005bc7f"
Fixed #32285 -- Raised ImproperlyConfigured when AppConfig.label is not a
valid Python identifier.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:10>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"110001d0bbbabe2a5b57b14a59bd0e4b71bf2712" 110001d]:
{{{
#!CommitTicketReference repository=""
revision="110001d0bbbabe2a5b57b14a59bd0e4b71bf2712"
Refs #32285 -- Made AppConfigStub do not call super().__init__().
Calling super().__init__() is unnecessary and enforces the use of
various workarounds.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:9>
Comment (by Simon Weber):
I was surprised by this error when trying to upgrade a large codebase to
3.2. This codebase's convention is to use app labels with dashes, which I
suspect still works fine (unlike labels with periods).
Is there a recommended migration path for projects like these that were
using an invalid label unknowingly? As far as I can tell, the only option
is to change the label, which looks involved: it affects things like old
migrations, db rows like content types, and maybe even table names.
If there's no simple migration path, what about changing this from an
exception to a warning? That'd still accomplish the goal of informing
users that something may break and allows cases like mine to avoid quite a
bit of pain.
--
Ticket URL: <https://code.djangoproject.com/ticket/32285#comment:11>