1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #29886 -- Fixed unaccent lookup when PostgreSQL's standard_conforming_strings option is off.

Thanks Tom McClure for the patch.
This commit is contained in:
Jayantha Gumballi
2018-11-01 20:44:34 +05:30
committed by Tim Graham
parent 74ddd0e83b
commit dfcdc8992f
2 changed files with 20 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
from django.db import connection
from django.test import modify_settings
from . import PostgreSQLTestCase
@@ -42,6 +43,24 @@ class UnaccentTest(PostgreSQLTestCase):
ordered=False
)
def test_unaccent_with_conforming_strings_off(self):
"""SQL is valid when standard_conforming_strings is off."""
with connection.cursor() as cursor:
cursor.execute('SHOW standard_conforming_strings')
disable_conforming_strings = cursor.fetchall()[0][0] == 'on'
if disable_conforming_strings:
cursor.execute('SET standard_conforming_strings TO off')
try:
self.assertQuerysetEqual(
self.Model.objects.filter(field__unaccent__endswith='éÖ'),
['àéÖ', 'aeO'],
transform=lambda instance: instance.field,
ordered=False,
)
finally:
if disable_conforming_strings:
cursor.execute('SET standard_conforming_strings TO on')
def test_unaccent_accentuated_needle(self):
self.assertQuerysetEqual(
self.Model.objects.filter(field__unaccent="aéÖ"),