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


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

The traceback, for reference (Django 1.8.1):

>           db_cfg = setup_databases(verbosity=0, interactive=False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.heroku/python/lib/python2.7/site-packages/django/test/ in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/ in create_test_db
    self._create_test_db(verbosity, autoclobber, keepdb)
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/ in _create_test_db
    with self._nodb_connection.cursor() as cursor:
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/ in cursor
    cursor = self.make_cursor(self._cursor())
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/ in _cursor
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/ in ensure_connection
.heroku/python/lib/python2.7/site-packages/django/db/ in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/ in ensure_connection
.heroku/python/lib/python2.7/site-packages/django/db/backends/base/ in connect
    self.connection = self.get_new_connection(conn_params)
.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/ in get_new_connection
    connection = Database.connect(**conn_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 


        if dsn is None:
            if not items:
                raise TypeError('missing dsn and no parameters')
                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/ OperationalError

Change History (9)

comment:1 by Daniel Hahler, 9 years ago

Cc: django@… added

comment:2 by Claude Paroz, 9 years ago

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

comment:3 by Claude Paroz, 9 years ago

#16969 has been resolved on the assumption that PostgreSQL users always have access to the postgres database (read
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 by Tim Graham, 9 years ago

I asked for feedback on the mailing list.

comment:5 by Claude Paroz, 9 years ago

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 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

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

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 by Claude Paroz <claude@…>, 9 years ago

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 by GitHub <noreply@…>, 6 years ago

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