summaryrefslogtreecommitdiff
path: root/django/db/backends/utils.py
diff options
context:
space:
mode:
authorDavid Sanders <shang.xiao.sanders@gmail.com>2023-09-24 19:02:50 +1000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-09-25 09:14:05 +0200
commit491092086929f90c048b606c58859f76238bcda2 (patch)
tree00ab760f2446e1fb9df9ad93c4f75bc220c86003 /django/db/backends/utils.py
parent81663cc4ca8f7ac0eac33cbb6986462330e75bb1 (diff)
[5.0.x] Fixed #34849 -- Avoided raising RuntimeWarning about import-time queries when apps are reinitialized with test tools.
Regression in fbd16438f46bc2128926958ad24331da5d1b406f. Backport of 4f2ae0644de34791b84b7beb11a966ce4bc48fb6 from main
Diffstat (limited to 'django/db/backends/utils.py')
-rw-r--r--django/db/backends/utils.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/django/db/backends/utils.py b/django/db/backends/utils.py
index 0aa94cc30b..f363253ca3 100644
--- a/django/db/backends/utils.py
+++ b/django/db/backends/utils.py
@@ -61,7 +61,9 @@ class CursorWrapper:
"Keyword parameters for callproc are not supported on this "
"database backend."
)
- if not apps.ready:
+ # Raise a warning during app initialization (stored_app_configs is only
+ # ever set during testing).
+ if not apps.ready and not apps.stored_app_configs:
warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)
self.db.validate_no_broken_transaction()
with self.db.wrap_database_errors:
@@ -90,7 +92,9 @@ class CursorWrapper:
return executor(sql, params, many, context)
def _execute(self, sql, params, *ignored_wrapper_args):
- if not apps.ready:
+ # Raise a warning during app initialization (stored_app_configs is only
+ # ever set during testing).
+ if not apps.ready and not apps.stored_app_configs:
warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)
self.db.validate_no_broken_transaction()
with self.db.wrap_database_errors:
@@ -101,7 +105,9 @@ class CursorWrapper:
return self.cursor.execute(sql, params)
def _executemany(self, sql, param_list, *ignored_wrapper_args):
- if not apps.ready:
+ # Raise a warning during app initialization (stored_app_configs is only
+ # ever set during testing).
+ if not apps.ready and not apps.stored_app_configs:
warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)
self.db.validate_no_broken_transaction()
with self.db.wrap_database_errors: