#34849: Appending django.contrib.postgres to the INSTALLED_APPS via
@modify_settings crashes.
-------------------------------------+-------------------------------------
               Reporter:  Mariusz    |          Owner:  nobody
  Felisiak                           |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  5.0
  layer (models, ORM)                |
               Severity:  Release    |       Keywords:
  blocker                            |
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Appending `django.contrib.postgres` to the `INSTALLED_APPS` via
 `@modify_settings` crashes with:
 {{{
 RuntimeWarning: Accessing the database during app initialization is
 discouraged. To fix this warning, avoid executing queries in
 AppConfig.ready() or when your app modules are imported.
 }}}
 Check out:
 {{{
 ./runtests.py postgres_tests
 ...
 ======================================================================
 ERROR: test_register_serializer_for_migrations
 (postgres_tests.test_apps.PostgresConfigTests)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/usr/local/lib/python3.10/unittest/case.py", line 59, in
 testPartExecutor
     yield
   File "/usr/local/lib/python3.10/unittest/case.py", line 591, in run
     self._callTestMethod(testMethod)
   File "/usr/local/lib/python3.10/unittest/case.py", line 549, in
 _callTestMethod
     method()
   File "/django/tests/postgres_tests/test_apps.py", line 64, in
 test_register_serializer_for_migrations
     with self.modify_settings(INSTALLED_APPS={"append":
 "django.contrib.postgres"}):
   File "/django/django/test/utils.py", line 405, in __enter__
     return self.enable()
   File "/django/django/test/utils.py", line 587, in enable
     super().enable()
   File "/django/django/test/utils.py", line 474, in enable
     apps.set_installed_apps(self.options["INSTALLED_APPS"])
   File "/django/django/apps/registry.py", line 362, in set_installed_apps
     self.populate(installed)
   File "/django/django/apps/registry.py", line 124, in populate
     app_config.ready()
   File "/django/django/contrib/postgres/apps.py", line 71, in ready
     register_type_handlers(conn)
   File "/django/django/contrib/postgres/signals.py", line 40, in
 register_type_handlers
     oids, array_oids = get_hstore_oids(connection.alias)
   File "/django/django/contrib/postgres/signals.py", line 24, in
 get_hstore_oids
     return get_type_oids(connection_alias, "hstore")
   File "/django/django/contrib/postgres/signals.py", line 10, in
 get_type_oids
     cursor.execute(
   File "/django/django/db/backends/utils.py", line 77, in execute
     return self._execute_with_wrappers(
   File "/django/django/db/backends/utils.py", line 90, in
 _execute_with_wrappers
     return executor(sql, params, many, context)
   File "/django/django/db/backends/utils.py", line 94, in _execute
     warnings.warn(self.APPS_NOT_READY_WARNING_MSG,
 category=RuntimeWarning)
 RuntimeWarning: Accessing the database during app initialization is
 discouraged. To fix this warning, avoid executing queries in
 AppConfig.ready() or when your app modules are imported.

 ======================================================================
 ERROR: test_register_type_handlers_connection
 (postgres_tests.test_apps.PostgresConfigTests)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/usr/local/lib/python3.10/unittest/case.py", line 59, in
 testPartExecutor
     yield
   File "/usr/local/lib/python3.10/unittest/case.py", line 591, in run
     self._callTestMethod(testMethod)
   File "/usr/local/lib/python3.10/unittest/case.py", line 549, in
 _callTestMethod
     method()
   File "/django/tests/postgres_tests/test_apps.py", line 36, in
 test_register_type_handlers_connection
     with modify_settings(INSTALLED_APPS={"append":
 "django.contrib.postgres"}):
   File "/django/django/test/utils.py", line 405, in __enter__
     return self.enable()
   File "/django/django/test/utils.py", line 587, in enable
     super().enable()
   File "/django/django/test/utils.py", line 474, in enable
     apps.set_installed_apps(self.options["INSTALLED_APPS"])
   File "/django/django/apps/registry.py", line 362, in set_installed_apps
     self.populate(installed)
   File "/django/django/apps/registry.py", line 124, in populate
     app_config.ready()
   File "/django/django/contrib/postgres/apps.py", line 71, in ready
     register_type_handlers(conn)
   File "/django/django/contrib/postgres/signals.py", line 40, in
 register_type_handlers
     oids, array_oids = get_hstore_oids(connection.alias)
   File "/django/django/contrib/postgres/signals.py", line 24, in
 get_hstore_oids
     return get_type_oids(connection_alias, "hstore")
   File "/django/django/contrib/postgres/signals.py", line 10, in
 get_type_oids
     cursor.execute(
   File "/django/django/db/backends/utils.py", line 77, in execute
     return self._execute_with_wrappers(
   File "/django/django/db/backends/utils.py", line 90, in
 _execute_with_wrappers
     return executor(sql, params, many, context)
   File "/django/django/db/backends/utils.py", line 94, in _execute
     warnings.warn(self.APPS_NOT_READY_WARNING_MSG,
 category=RuntimeWarning)
 RuntimeWarning: Accessing the database during app initialization is
 discouraged. To fix this warning, avoid executing queries in
 AppConfig.ready() or when your app modules are imported.

 ----------------------------------------------------------------------
 Ran 590 tests in 1.840s

 FAILED (errors=2, skipped=8, expected failures=3)
 }}}

 `@modify_settings` repopulates apps that register type handlers and hits
 the database to select OIDs (if not cached).

 Regression in fbd16438f46bc2128926958ad24331da5d1b406f (#33143).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34849>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018aac3d343c-df6a3e26-99c7-4683-ad6a-0603a34fa903-000000%40eu-central-1.amazonses.com.

Reply via email to