Skip to content

Commit b29f745

Browse files
committed
Fix query to do an exact compares
1 parent 49f6425 commit b29f745

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

readthedocs/redirects/querysets.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ def get_redirect_path_with_status(self, path, full_path=None, language=None, ver
5050
1,
5151
F('from_length') - 5 # Strip "$rest"
5252
),
53+
54+
# 1-indexed
55+
full_path_without_rest=Substr(
56+
'full_path',
57+
1,
58+
F('from_length') - 5 # Strip "$rest"
59+
),
5360
)
5461
prefix = Q(
5562
redirect_type='prefix',
@@ -62,8 +69,11 @@ def get_redirect_path_with_status(self, path, full_path=None, language=None, ver
6269
exact = (
6370
Q(
6471
redirect_type='exact',
65-
from_url__endswith='$rest', # Python implementation does "in"
66-
full_path__startswith=F('from_url_without_rest'),
72+
from_url__endswith='$rest',
73+
# This works around a bug in Django doing a substr and an endswith,
74+
# so instead we do 2 substrs and an exact
75+
# https://code.djangoproject.com/ticket/29155
76+
full_path_without_rest=F('from_url_without_rest'),
6777
) | Q(
6878
redirect_type='exact',
6979
full_path__iexact=F('from_url'),

0 commit comments

Comments
 (0)