Opened 3 weeks ago

Closed 5 days ago

Last modified 24 hours ago

#29469 closed Bug (fixed)

Misleading makemigrations "App count not be found" error message with nested apps

Reported by: Matthew Schinckel Owned by: oliver
Component: Migrations Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a couple of nested apps, or apps that are not available directly in the top-level namespace.

When you use makemigrations, and pass the full dotted path to this command, the error message is somewhat misleading:

App 'integrations.systems.generic.importers' could not be found. Is it in INSTALLED_APPS?

In this case, I have that exact string in my INSTALLED_APPS, but makemigrations is expecting just the app_label. Perhaps we could improve the error message when dots are detected in the app_label, suggesting how to fix it: or even look at just the last part of the path?

Change History (10)

comment:1 Changed 3 weeks ago by Matthew Schinckel

Component: UncategorizedMigrations

comment:2 Changed 2 weeks ago by Windson yang

Maybe you should add an example project?

comment:3 Changed 2 weeks ago by Tim Graham

Summary: Makemigrations provides misleading error message.Misleading makemigrations "App count not be found" error message with nested apps
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:6 Changed 7 days ago by oliver

Owner: set to oliver
Status: newassigned

comment:7 Changed 7 days ago by oliver

Current code generating that error message is as follows when using makemigraions command.

       # Make sure the app they asked for exists
        app_labels = set(app_labels)
        bad_app_labels = set()
        for app_label in app_labels:
            try:
                apps.get_app_config(app_label)
            except LookupError:
                bad_app_labels.add(app_label)
        if bad_app_labels:
            for app_label in bad_app_labels:
                self.stderr.write("App '%s' could not be found. Is it in INSTALLED_APPS?" % app_label)
            sys.exit(2)

and below is the part that checks the validity of the app name when using startapp and createproject command

        if not name.isidentifier():
            raise CommandError(
                "'{name}' is not a valid {app} name. Please make sure the "
                "name is a valid identifier.".format(
                    name=name,
                    app=app_or_project,
                )
            )

How about using the code validating app name to current code as follows?
https://github.com/django/django/pull/10052

       # Make sure the app they asked for is a valid app name and exist.
        app_labels = set(app_labels)
        bad_app_labels = set()
        for app_label in app_labels:
            try:
                apps.get_app_config(app_label)
            except LookupError:
                bad_app_labels.add(app_label)
        if bad_app_labels:
            for app_label in bad_app_labels:
                if not app_label.isidentifier():
                    self.stderr.write(
                        "'%s' is not a valid app name. Please make sure the "
                        "name is a valid identifier." % app_label
                    )
                else:
                    self.stderr.write("App '%s' could not be found. Is it in INSTALLED_APPS?" % app_label)
            sys.exit(2)
Last edited 7 days ago by oliver (previous) (diff)

comment:8 Changed 6 days ago by Tim Graham

Has patch: set
Needs tests: set

comment:9 Changed 5 days ago by oliver

https://github.com/django/django/pull/10057

I change the target branch to master and add a test.

comment:10 Changed 5 days ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 78972af3:

Fixed #29469 -- Added a helpful makemigrations error if app_label contains dots.

comment:11 Changed 5 days ago by Tim Graham <timograham@…>

In d03b130c:

[2.1.x] Fixed #29469 -- Added a helpful makemigrations error if app_label contains dots.

Backport of 78972af367a1da54aa7e539e4b1ffa2b56571e77 from master

comment:12 Changed 24 hours ago by Tim Graham <timograham@…>

In c3c7d15:

Refs #29469 -- Reused get_app_config() error message in makemigrations error.

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