#35902: Postgres extensions not enabled in test DB when running pytest --no-
migrations
-------------------------------------+-------------------------------------
               Reporter:  wadhah101  |          Owner:  wadhah101
                   Type:             |         Status:  assigned
  Uncategorized                      |
              Component:  Database   |        Version:  5.1
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  1
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  1
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 When running tests with `pytest --no-migration,` postgres extensions
 required by model indexes are not automatically enabled in the test
 database. This causes migration to fail when models contain indexes that
 depend on postgres extensions like pg_trgm.

 to reproduce it's enough to run `pytest --no-migrations`
 and have a model like


 {{{
 from django.db import models
 from django.contrib.postgres.indexes import GinIndex
 from django.contrib.postgres.operations import OpClass
 from django.db.models.functions import Lower

 class User(models.Model):
     first_name = models.CharField(max_length=255)
     last_name = models.CharField(max_length=255)
     email = models.EmailField(unique=True)
     created_at = models.DateTimeField(auto_now_add=True)
     updated_at = models.DateTimeField(auto_now=True)

     class Meta:
         indexes = [
             GinIndex(
                 OpClass(
                     Lower("first_name"),
                     name="gin_trgm_ops",
                 ),
                 OpClass(
                     Lower("last_name"),
                     name="gin_trgm_ops",
                 ),
                 name="user_name_trgm_idx",
             ),
         ]
 }}}



 this will produce


 {{{
     def _execute(self, sql, params, *ignored_wrapper_args):
         self.db.validate_no_broken_transaction()
         with self.db.wrap_database_errors:
             if params is None:
                 # params default might be backend specific.
 >               return self.cursor.execute(sql)
 E               django.db.utils.ProgrammingError: operator class
 "gin_trgm_ops" does not exist for access method "gin"
 }}}


 The easy fix and the most expected by user is for `create_test_db` to copy
 existing and enabled extensions
 I am willing to contribute if maintainer agree on the fix
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35902>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019315746c30-409ce1d6-7610-439b-bd2a-22c7df0117f1-000000%40eu-central-1.amazonses.com.

Reply via email to