Opened 7 years ago

Closed 7 years ago

#28463 closed Bug (invalid)

Custom migrations that create a postgres role run against the production database during tests (postgres 9.6)

Reported by: Simon Tomlinson Owned by: nobody
Component: Testing framework Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Creating a custom migration that uses migrations.RunSQL to create a new postgres role and then running tests using python manage.py test creates the role in the real postgres server (when running postgres 9.6).

This doesn't happen with other custom sql, such as creating a type, which I found very odd.

Attached is a django project configured to connect to a postgres database running on localhost:5432, with a "postgres" user with no password and a postgres database. It contains an app called "app" with a single migration that executes CREATE ROLE test_role.

Run python manage.py test and then inspect the database to reproduce. The role test_role should exist (list it with \du in psql).
Alternatively, run python manage.py test twice. It will crash the second time because the role already exists from the first run.

Attachments (1)

migration_role_test.tar.gz (4.2 KB ) - added by Simon Tomlinson 7 years ago.
Django project exhibiting the problem

Download all attachments as: .zip

Change History (2)

by Simon Tomlinson, 7 years ago

Attachment: migration_role_test.tar.gz added

Django project exhibiting the problem

comment:1 by Simon Tomlinson, 7 years ago

Resolution: invalid
Status: newclosed

I just realized that roles aren't database specific. Of course this happens.

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