Opened 4 years ago

Closed 4 years ago

#31870 closed Bug (fixed)

App with default_app_config and without apps.py or with an empty apps.py crashes.

Reported by: Iuri de Silvio Owned by: Iuri de Silvio
Component: Core (Other) Version: dev
Severity: Release blocker Keywords:
Cc: Aymeric Augustin Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Iuri de Silvio)

If I don't have an apps.py and the default_app_config is in __init__.py, it fails.

Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    main()
  File "./manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "django/apps/config.py", line 157, in create
    if new_entry == app_config_name:
UnboundLocalError: local variable 'app_config_name' referenced before assignment

If the apps.py is there, but the default_app_config is in __init__.py, it fails too.

Traceback (most recent call last):
  File "django/django/test/utils.py", line 381, in inner
    return func(*args, **kwargs)
  File "django/tests/apps/tests.py", line 541, in test_explicit_default_app_config_with_empty_apps
    with self.settings(INSTALLED_APPS=['apps.explicit_default_config_with_empty_apps']):
  File "django/django/test/utils.py", line 336, in __enter__
    return self.enable()
  File "django/django/test/utils.py", line 410, in enable
    apps.set_installed_apps(self.options['INSTALLED_APPS'])
  File "django/django/apps/registry.py", line 355, in set_installed_apps
    self.populate(installed)
  File "django/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "django/django/apps/config.py", line 160, in create
    if new_entry == app_config_name:
UnboundLocalError: local variable 'app_config_name' referenced before assignment

Looks like a regression added in https://code.djangoproject.com/ticket/31180.

Change History (7)

comment:1 by Iuri de Silvio, 4 years ago

Owner: changed from nobody to Iuri de Silvio
Status: newassigned

comment:2 by Iuri de Silvio, 4 years ago

Description: modified (diff)

comment:3 by Mariusz Felisiak, 4 years ago

Cc: Aymeric Augustin added
Component: UncategorizedCore (Other)
Has patch: set
Patch needs improvement: set
Severity: NormalRelease blocker
Summary: App with default_app_config in init crashesApp with default_app_config and without apps.py or with an empty apps.py crashes.
Triage Stage: UnreviewedAccepted
Version: 3.1master

Thanks for the report.

Regression in 3f2821af6bc48fa8e7970c1ce27bc54c3172545e.
Reproduced at b2b0711b555fa292751763c2df4fe577c396f265.

Version 0, edited 4 years ago by Mariusz Felisiak (next)

comment:4 by Iuri de Silvio, 4 years ago

Patch needs improvement: unset

comment:5 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Aymeric Augustin, 4 years ago

The PR is very good. Thanks.

comment:7 by GitHub <noreply@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In ebd78a9f:

Fixed #31870 -- Fixed crash when populating app registry with empty or without apps module.

Regression in 3f2821af6bc48fa8e7970c1ce27bc54c3172545e.

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