2
2
3
3
import logging
4
4
5
- from django .db import models , DataError
6
- from django .db .models import Value , CharField , IntegerField , Q , F , ExpressionWrapper
7
- from django .db .models .functions import Substr , Length
5
+ from django .db import models
6
+ from django .db .models import Value , CharField , Q , F
8
7
9
8
from readthedocs .core .utils .extend import SettingsOverrideObject
10
9
@@ -42,27 +41,6 @@ def get_redirect_path_with_status(self, path, full_path=None, language=None, ver
42
41
full_path ,
43
42
output_field = CharField (),
44
43
),
45
-
46
- from_url_length = ExpressionWrapper (
47
- Length ('from_url' ),
48
- output_field = IntegerField (),
49
- ),
50
-
51
- # 1-indexed
52
- from_url_without_rest = Substr (
53
- 'from_url' ,
54
- 1 ,
55
- F ('from_url_length' ) - 5 , # Strip "$rest"
56
- output_field = CharField (),
57
- ),
58
-
59
- # 1-indexed
60
- full_path_without_rest = Substr (
61
- 'full_path' ,
62
- 1 ,
63
- F ('from_url_length' ) - 5 , # Strip "$rest"
64
- output_field = CharField (),
65
- ),
66
44
)
67
45
prefix = Q (
68
46
redirect_type = 'prefix' ,
@@ -76,10 +54,7 @@ def get_redirect_path_with_status(self, path, full_path=None, language=None, ver
76
54
Q (
77
55
redirect_type = 'exact' ,
78
56
from_url__endswith = '$rest' ,
79
- # This works around a bug in Django doing a substr and an endswith,
80
- # so instead we do 2 substrs and an exact
81
- # https://code.djangoproject.com/ticket/29155
82
- full_path_without_rest = F ('from_url_without_rest' ),
57
+ full_path__startswith = F ('from_url_without_rest' ),
83
58
) | Q (
84
59
redirect_type = 'exact' ,
85
60
full_path__iexact = F ('from_url' ),
@@ -99,20 +74,7 @@ def get_redirect_path_with_status(self, path, full_path=None, language=None, ver
99
74
path__endswith = '.html' ,
100
75
)
101
76
102
- try :
103
- # Using the ``exact`` Q object we created here could cause an
104
- # execption because it uses ``from_url_without_rest`` and
105
- # ``full_path_without_rest`` which could produce a database error
106
- # ("negative substring length not allowed") when ``from_url``'s
107
- # length is less than 5 ('$rest' string substracted from it). We
108
- # perform a query using ``exact`` here and if it fail we catch it
109
- # and just ignore these redirects for this project.
110
- queryset = queryset .filter (prefix | page | exact | sphinx_html | sphinx_htmldir )
111
- queryset .select_related ('project' ).count ()
112
- except DataError :
113
- # Fallback to the query without using ``exact`` on it
114
- log .warning ('Failing Exact Redirects on this project. Ignoring them.' )
115
- queryset = queryset .filter (prefix | page | sphinx_html | sphinx_htmldir )
77
+ queryset = queryset .filter (prefix | page | exact | sphinx_html | sphinx_htmldir )
116
78
117
79
# There should be one and only one redirect returned by this query. I
118
80
# can't think in a case where there can be more at this point. I'm
0 commit comments