Skip to content

Commit 693dcee

Browse files
authored
Domains: don't run CNAME checks on domain updates (#12564)
This check only makes sense when adding a new domain, not when updating. And on .com, the target CNAME is a domain that points to another CNAME, so the check always fails after a valid domain is added. The domain field is set to read-only, so this is fine.
1 parent 8c4761a commit 693dcee

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

readthedocs/projects/forms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,9 @@ def clean_domain(self):
10201020
if invalid_domain and domain_string.endswith(invalid_domain):
10211021
raise forms.ValidationError(f"{invalid_domain} is not a valid domain.")
10221022

1023-
self._check_for_suspicious_cname(domain_string)
1023+
# Run this check only on domain creation.
1024+
if not self.instance.pk:
1025+
self._check_for_suspicious_cname(domain_string)
10241026

10251027
return domain_string
10261028

readthedocs/projects/tests/test_domain_views.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ def test_create_domain_with_single_cname(self, dns_resolve_mock):
173173
domain = self.project.domains.first()
174174
assert domain.domain == "docs.example.com"
175175

176+
@mock.patch("readthedocs.projects.forms.dns.resolver.resolve")
177+
def test_editing_domain_doesnt_trigger_cname_validation(self, dns_resolve_mock):
178+
domain = get(Domain, project=self.project, domain="docs.example.com")
179+
assert not domain.canonical
180+
resp = self.client.post(
181+
reverse("projects_domains_edit", args=[self.project.slug, domain.pk]),
182+
data={"canonical": True},
183+
)
184+
assert resp.status_code == 302
185+
domain.refresh_from_db()
186+
assert domain.canonical
187+
dns_resolve_mock.assert_not_called()
188+
176189
@override_settings(
177190
RTD_DEFAULT_FEATURES=dict(
178191
[RTDProductFeature(type=TYPE_CNAME, value=1).to_item()]

0 commit comments

Comments
 (0)