You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
…/django/db/backends/utils.py:98: 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.
warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)
Commenting these out breaks the code, but suppresses the warning:
defupdate_coding_system_database_connections():
"""Add the database config for each coding system release"""# ensure that the database is ready and the CodingSystemRelease table is available# (i.e. migrations have been run)# Remove database_ready() check from original code as that access the database:# if database_ready(): # pragma: no cover# The original code iterates through CodingSystemRelease.objects.all()forcoding_system_releasein []:
ifnotCODING_SYSTEMS[coding_system_release.coding_system].has_database:
continuedb_path= (
settings.CODING_SYSTEMS_DATABASE_DIR/coding_system_release.coding_system/f"{coding_system_release.database_alias}.sqlite3"
)
database_dict= {
**connections.databases[DEFAULT_DB_ALIAS],
**dj_database_url.parse(f"sqlite:///{db_path}"),
}
connections.databases[coding_system_release.database_alias] =database_dict
This is not something that currently breaks anything, but could in future if the warning behaviour is forbidden by Django in future. It's also discouraged by the relevant Django documentation, at least for Django 5.1.
The text was updated successfully, but these errors were encountered:
StevenMaude
changed the title
Remove coding system database setup from in AppConfig.ready()
Refactor coding system database setup in AppConfig.ready()Jan 9, 2025
In Django 5 and up, we get the following warning:
This is because of a call in
AppConfig.ready()
.That call in turn results in the following lines running that access the database:
opencodelists/coding_systems/versioning/models.py
Lines 62 to 68 in 772c560
opencodelists/coding_systems/versioning/models.py
Line 76 in 772c560
Commenting these out breaks the code, but suppresses the warning:
This is not something that currently breaks anything, but could in future if the warning behaviour is forbidden by Django in future. It's also discouraged by the relevant Django documentation, at least for Django 5.1.
The text was updated successfully, but these errors were encountered: