django-prometheus icon indicating copy to clipboard operation
django-prometheus copied to clipboard

migrations causes ./manage collectstatic to fail without db

Open ecksun opened this issue 8 years ago • 5 comments

When I try to do collectstatic with PROMETHEUS_EXPORT_MIGRATIONS = True it fails with the following error:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
    django.setup()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django_prometheus/apps.py", line 24, in ready
    ExportMigrations()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django_prometheus/migrations.py", line 46, in ExportMigrations
    executor = MigrationExecutor(connections[alias])
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 176, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
    self.ensure_schema()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 233, in cursor
    cursor = self.make_cursor(self._cursor())
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor
    self.ensure_connection()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 175, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: No route to host
        Is the server running on host "databaseserver.example.com" (127.1.2.3) and accepting
        TCP/IP connections on port 5432?

However with PROMETHEUS_EXPORT_MIGRATIONS = True everything works fine.

Running collectstatic should not require a database connection.

ecksun avatar Feb 14 '17 12:02 ecksun

@ecksun PROMETHEUS_EXPORT_MIGRATIONS = False disables django-prometheus ExportMigrations() https://github.com/korfuri/django-prometheus/blob/v1.0.10/django_prometheus/apps.py#L23

robertobarreda avatar Oct 31 '17 14:10 robertobarreda

Yes, I think thats what I tried to say but mistyped in my original comment (though I barely remember this issue).

The issue still stands though, it makes no sense that collectstatic has dependencies on the database.

ecksun avatar Oct 31 '17 22:10 ecksun

I think it'd be nice if this setting defaulted to False

arma26 avatar Jan 26 '18 22:01 arma26

@korfuri as per our email ...

I encountered this same issue both in our Jenkins CI environment and our SCM test kitchen. It would be highly preferable if django_prometheus was agnostic to database activity. This seems to be the only offending functionality

The Error https://gist.github.com/nsfyn55/6a84438f8ccd3a9e5af688bdc644cdbc

The Offending Line https://github.com/korfuri/django-prometheus/blob/9e77122ac95da695d3de3742cd2e10c11e8c112f/django_prometheus/migrations.py#L46

nsfyn55 avatar Mar 30 '18 16:03 nsfyn55

+1 affects a number of non db related scenarios such as collectstatic which at build causes big issues

rosscdh avatar Apr 11 '20 10:04 rosscdh