mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #29915 -- Added support for values with hyphens to pattern lookups for UUIDField on backends without UUID datatype.
Support hyphens in iexact, contains, icontains, startswith, istartswith, endswith and iendswith UUIDField filters on backends without UUID datatype.
This commit is contained in:
committed by
Mariusz Felisiak
parent
343afa7880
commit
d9881a025c
@@ -4,7 +4,7 @@ import uuid
|
||||
from django.core import exceptions, serializers
|
||||
from django.db import IntegrityError, connection, models
|
||||
from django.db.models import CharField, F, Value
|
||||
from django.db.models.functions import Concat
|
||||
from django.db.models.functions import Concat, Repeat
|
||||
from django.test import (
|
||||
SimpleTestCase, TestCase, TransactionTestCase, skipUnlessDBFeature,
|
||||
)
|
||||
@@ -121,6 +121,12 @@ class TestQuerying(TestCase):
|
||||
),
|
||||
[self.objs[1]],
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
NullableUUIDModel.objects.filter(
|
||||
field__iexact='550E8400-E29B-41D4-A716-446655440000'
|
||||
),
|
||||
[self.objs[1]],
|
||||
)
|
||||
|
||||
def test_isnull(self):
|
||||
self.assertSequenceEqual(
|
||||
@@ -133,36 +139,60 @@ class TestQuerying(TestCase):
|
||||
NullableUUIDModel.objects.filter(field__contains='8400e29b'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
NullableUUIDModel.objects.filter(field__contains='8400-e29b'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
|
||||
def test_icontains(self):
|
||||
self.assertSequenceEqualWithoutHyphens(
|
||||
NullableUUIDModel.objects.filter(field__icontains='8400E29B'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
NullableUUIDModel.objects.filter(field__icontains='8400-E29B'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
|
||||
def test_startswith(self):
|
||||
self.assertSequenceEqualWithoutHyphens(
|
||||
NullableUUIDModel.objects.filter(field__startswith='550e8400e29b4'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
NullableUUIDModel.objects.filter(field__startswith='550e8400-e29b-4'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
|
||||
def test_istartswith(self):
|
||||
self.assertSequenceEqualWithoutHyphens(
|
||||
NullableUUIDModel.objects.filter(field__istartswith='550E8400E29B4'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
NullableUUIDModel.objects.filter(field__istartswith='550E8400-E29B-4'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
|
||||
def test_endswith(self):
|
||||
self.assertSequenceEqualWithoutHyphens(
|
||||
NullableUUIDModel.objects.filter(field__endswith='a716446655440000'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
NullableUUIDModel.objects.filter(field__endswith='a716-446655440000'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
|
||||
def test_iendswith(self):
|
||||
self.assertSequenceEqualWithoutHyphens(
|
||||
NullableUUIDModel.objects.filter(field__iendswith='A716446655440000'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
NullableUUIDModel.objects.filter(field__iendswith='A716-446655440000'),
|
||||
[self.objs[1]],
|
||||
)
|
||||
|
||||
def test_filter_with_expr(self):
|
||||
self.assertSequenceEqualWithoutHyphens(
|
||||
@@ -171,6 +201,18 @@ class TestQuerying(TestCase):
|
||||
).filter(field__contains=F('value')),
|
||||
[self.objs[1]],
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
NullableUUIDModel.objects.annotate(
|
||||
value=Concat(Value('8400'), Value('-'), Value('e29b'), output_field=CharField()),
|
||||
).filter(field__contains=F('value')),
|
||||
[self.objs[1]],
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
NullableUUIDModel.objects.annotate(
|
||||
value=Repeat(Value('0'), 4, output_field=CharField()),
|
||||
).filter(field__contains=F('value')),
|
||||
[self.objs[1]],
|
||||
)
|
||||
|
||||
|
||||
class TestSerialization(SimpleTestCase):
|
||||
|
||||
Reference in New Issue
Block a user