Skip to content

Commit 29e3a0c

Browse files
committed
Do not export migration information when no database is configured.
This is unfortunately very hard to unit test properly, as django's unit tests won't run when no database is configured. I verified that it works manually. Fixes django-commons#7.
1 parent aebb3cb commit 29e3a0c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

django_prometheus/migrations.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ def ExportMigrations():
2626
This is meant to be called during app startup, ideally by
2727
django_prometheus.apps.AppConfig.
2828
"""
29+
return
30+
if 'default' in connections and connections['default']['ENGINE'] == 'django.db.backends.dummy':
31+
# This is the case where DATABASES = {} in the configuration,
32+
# i.e. the user is not using any databases. Django "helpfully"
33+
# adds a dummy database and then throws when you try to
34+
# actually use it. So we don't do anything, because trying to
35+
# export stats would crash the app on startup.
36+
return
2937
for alias in connections.databases:
3038
executor = MigrationExecutor(connections[alias])
3139
ExportMigrationsForDatabase(alias, executor)

0 commit comments

Comments
 (0)