Opened 9 years ago

Closed 9 years ago

Last modified 6 years ago

#24791 closed Bug (fixed)

Cannot run tests without access to postgres database

Reported by: Daniel Hahler Owned by: nobody
Component: Testing framework Version: 1.8
Severity: Release blocker Keywords:
Cc: django@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The change for ticket #16969 prevents Django from being able to run tests on Heroku,
here you are not allowed to connect to the "postgres" database, at least with the free tier.

Would it be an option to use an explicitly configured
DATABASES['default']['TEST']['NAME'] setting, instead of 'postgres' here?

Or could there be a new setting, like
DATABASES['default']['TEST']['CONNECT_NAME']?

The traceback, for reference (Django 1.8.1):

.heroku/python/lib/python2.7/site-packages/pytest_django/fixtures.py:53: 
>           db_cfg = setup_databases(verbosity=0, interactive=False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.heroku/python/lib/python2.7/site-packages/django/test/runner.py:370: in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/creation.py:354: in create_test_db
    self._create_test_db(verbosity, autoclobber, keepdb)
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/creation.py:447: in _create_test_db
    with self._nodb_connection.cursor() as cursor:
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/base.py:164: in cursor
    cursor = self.make_cursor(self._cursor())
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/base.py:135: in _cursor
    self.ensure_connection()
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/base.py:130: in ensure_connection
    self.connect()
.heroku/python/lib/python2.7/site-packages/django/db/utils.py:97: in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/base.py:130: in ensure_connection
    self.connect()
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/base.py:119: in connect
    self.connection = self.get_new_connection(conn_params)
.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py:172: in get_new_connection
    connection = Database.connect(**conn_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    ...

        if dsn is None:
            if not items:
                raise TypeError('missing dsn and no parameters')
            else:
                dsn = " ".join(["%s=%s" % (k, _param_escape(str(v)))
                    for (k, v) in items])

>       conn = _connect(dsn, connection_factory=connection_factory, async=async)
E       OperationalError: FATAL:  permission denied for database "postgres"
E       DETAIL:  User does not have CONNECT privilege.

.heroku/python/lib/python2.7/site-packages/psycopg2/__init__.py:164: OperationalError

Change History (9)

comment:1 Changed 9 years ago by Daniel Hahler

Cc: django@… added

comment:2 Changed 9 years ago by Claude Paroz

#24795 was closed as a duplicate (affecting PostGIS user).

comment:3 Changed 9 years ago by Claude Paroz

#16969 has been resolved on the assumption that PostgreSQL users always have access to the postgres database (read https://code.djangoproject.com/ticket/16969#comment:4).
Now either the bug is on Heroku's side and they should grant at least the CONNECT privilege to all of their users, or we decide that our assumption was wrong and we should at least partially revert our patch, or find a workaround. Thoughts?

comment:4 Changed 9 years ago by Tim Graham

I asked for feedback on the mailing list.

comment:5 Changed 9 years ago by Claude Paroz

Has patch: set

In this PR, I tried to fallback to the database of the current connection when the 'postgres' db isn't available. Might be an acceptable path...

comment:6 Changed 9 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:7 Changed 9 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In 32260503:

Fixed #24791 -- Added fallback when 'postgres' database isn't available

Thanks Carl Meyer and Tim Graham for the reviews.

comment:8 Changed 9 years ago by Claude Paroz <claude@…>

In cdf7f90:

[1.8.x] Fixed #24791 -- Added fallback when 'postgres' database isn't available

Thanks Carl Meyer and Tim Graham for the reviews.
Backport of 322605035 from master.

comment:9 Changed 6 years ago by GitHub <noreply@…>

In 816b386d:

Refs #24791 -- Made PostgreSQL's nodb connection use first PostgresSQL db when 'postgres' db isn't available.

Thanks Tim Graham and Claude Paroz for reviews.

Note: See TracTickets for help on using tickets.
Back to Top