Skip to content

Commit aa0ed88

Browse files
authored
Proxito: ease migration to custom path prefixes (#10448)
With this, we would be able to start generating links using the path-prefix while serving docs with the old proxito implementation. And this also allows us to start using the new implementation with just enabling the feature flag for a project. This is, without having to unset the `urlconf` attribute. This helps us to have zero downtime while migrating projects.
1 parent 390cf44 commit aa0ed88

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

readthedocs/core/resolver.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,13 @@ def base_resolve_path(
9999

100100
# TODO: remove this when all projects have migrated to path prefixes.
101101
# Allow users to override their own URLConf
102-
# This logic could be cleaned up with a standard set of variable replacements
103-
if urlconf:
102+
# If a custom prefix is given, we don't use the custom URLConf,
103+
# since they are not compatible with each other.
104+
# We also don't check if the project has the new proxito implementation
105+
# enabled, this is so we can start generating links with the new
106+
# custom prefixes without starting to serve docs with it (this helps to ease
107+
# the migration from urlconf to custom prefixes).
108+
if urlconf and not custom_prefix:
104109
path = urlconf
105110
path = path.replace(
106111
"$version",

readthedocs/proxito/middleware.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class ProxitoMiddleware(MiddlewareMixin):
4848
'embed_api',
4949
)
5050

51-
# pylint: disable=no-self-use
5251
def add_proxito_headers(self, request, response):
5352
"""Add debugging and cache headers to proxito responses."""
5453

@@ -217,22 +216,22 @@ def process_request(self, request): # noqa
217216
raise DomainDNSHttp404(
218217
http_status=400,
219218
domain=exc.domain,
220-
)
219+
) from exc
221220
except (InvalidSubdomainError, InvalidExternalDomainError) as exc:
222221
log.debug("Invalid project set on the subdomain.")
223222
# Raise a contextualized 404 that will be handled by proxito's 404 handler
224223
raise ProjectHttp404(
225224
domain=exc.domain,
226-
)
225+
) from exc
227226
except InvalidCustomDomainError as exc:
228227
# Some person is CNAMEing to us without configuring a domain - 404.
229228
log.debug("CNAME 404.", domain=exc.domain)
230229
# Raise a contextualized 404 that will be handled by proxito's 404 handler
231230
raise DomainDNSHttp404(
232231
domain=exc.domain,
233-
)
234-
except InvalidXRTDSlugHeaderError:
235-
raise SuspiciousOperation("Invalid X-RTD-Slug header.")
232+
) from exc
233+
except InvalidXRTDSlugHeaderError as exc:
234+
raise SuspiciousOperation("Invalid X-RTD-Slug header.") from exc
236235

237236
self._set_request_attributes(request, unresolved_domain)
238237

@@ -269,8 +268,9 @@ def process_request(self, request): # noqa
269268

270269
# This is hacky because Django wants a module for the URLConf,
271270
# instead of also accepting string
272-
if project.urlconf:
273-
271+
if project.urlconf and not project.has_feature(
272+
Feature.USE_UNRESOLVER_WITH_PROXITO
273+
):
274274
# Stop Django from caching URLs
275275
# https://github.com/django/django/blob/7cf7d74/django/urls/resolvers.py#L65-L69 # noqa
276276
project_timestamp = project.modified_date.strftime("%Y%m%d.%H%M%S%f")

0 commit comments

Comments
 (0)