New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrations causes ./manage collectstatic to fail without db #34

Open
ecksun opened this Issue Feb 14, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@ecksun

ecksun commented Feb 14, 2017

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.

@robertobarreda

This comment has been minimized.

robertobarreda commented Oct 31, 2017

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

@ecksun

This comment has been minimized.

ecksun commented Oct 31, 2017

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.

@arma26

This comment has been minimized.

arma26 commented Jan 26, 2018

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

@nsfyn55

This comment has been minimized.

nsfyn55 commented Mar 30, 2018

@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

executor = MigrationExecutor(connections[alias])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment