Opened 6 years ago

Closed 6 years ago

Last modified 6 years 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 by Matthew Schinckel, 6 years ago

Component: UncategorizedMigrations

comment:2 by Windson yang, 6 years ago

Maybe you should add an example project?

comment:3 by Tim Graham, 6 years ago

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 by oliver, 6 years ago

Owner: set to oliver
Status: newassigned

comment:7 by oliver, 6 years ago

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/10051

       # 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 identifire."% app_label
                    )
                else:
                    self.stderr.write("App '%s' could not be found. Is it in INSTALLED_APPS?" % app_label)
            sys.exit(2)
Version 0, edited 6 years ago by oliver (next)

comment:8 by Tim Graham, 6 years ago

Has patch: set
Needs tests: set

comment:9 by oliver, 6 years ago

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

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

comment:10 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 78972af3:

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

comment:11 by Tim Graham <timograham@…>, 6 years ago

In d03b130c:

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

Backport of 78972af367a1da54aa7e539e4b1ffa2b56571e77 from master

comment:12 by Tim Graham <timograham@…>, 6 years ago

In c3c7d15:

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

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