Opened 3 weeks ago

Closed 11 days ago

#36985 closed Cleanup/optimization (fixed)

Reversing CreateExtension throws error on non-postgresql database

Reported by: Jori Niemi Owned by: Varun Kasyap Pentamaraju
Component: contrib.postgres Version: 6.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

When run on sqlite, a migration using postgres CreateExtension will skip creating the extension. Trying to reverse the migration throws an error:

django.db.utils.OperationalError: no such table: pg_extension

I assume this is because CreateExtension.database_forwards checks schema_editor.connection.vendor != "postgresql" but CreateExtension.database_backwards does not.

Minimal migration example:

from django.db import migrations
from django.contrib.postgres.operations import CreateExtension

class Migration(migrations.Migration):
    dependencies = []

    operations = [
        CreateExtension("pg_trgm")
    ]

Change History (10)

comment:1 by Lakshya Prasad, 3 weeks ago

I can reproduce this issue locally. Reversing CreateExtension on a
non-PostgreSQL database raises an error. The operation should likely
be skipped when the connection vendor is not PostgreSQL.

I’d like to work on a fix if the ticket is accepted.

comment:2 by Jacob Walls, 2 weeks ago

Easy pickings: set
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Ok, let's have this. Interestingly, this graceful skip in the forward direction was only added for Django's own test suite in 36e90d1f45a13f53ce25fdc2d9c04433b835c9af.

comment:3 by Varun Kasyap Pentamaraju, 2 weeks ago

Owner: set to Varun Kasyap Pentamaraju
Status: newassigned

comment:4 by Lakshya Prasad, 2 weeks ago

Hi Varun, are you currently working on this ticket? If not, I’d be happy to contribute a fix.

in reply to:  4 comment:5 by Varun Kasyap Pentamaraju, 2 weeks ago

Replying to Lakshya Prasad:

Hi Varun, are you currently working on this ticket? If not, I’d be happy to contribute a fix.

Hi Lakshya,
I have a patch and will be submitting soon. Thanks

comment:6 by Varun Kasyap Pentamaraju, 13 days ago

Has patch: set

comment:7 by Varun Kasyap Pentamaraju, 12 days ago

Patch needs improvement: set

comment:8 by Varun Kasyap Pentamaraju, 12 days ago

Patch needs improvement: unset

comment:9 by Jacob Walls, 11 days ago

Triage Stage: AcceptedReady for checkin

comment:10 by Jacob Walls <jacobtylerwalls@…>, 11 days ago

Resolution: fixed
Status: assignedclosed

In b38cddf8:

Fixed #36985 -- Skipped CreateExtension backwards operation on non-PostgreSQL databases.

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