Skip to content

Commit c7c96de

Browse files
authored
Project: use get_original_latest_version in form (#12460)
This is the same logic we have in https://github.com/readthedocs/readthedocs.org/blob/a8a29fe29292027a4e2a44cc468cea4adc70e390/readthedocs/projects/models.py#L1164-L1181 and it already excludes latest I'm doing small refactors to rely less on get_default_branch, as that contains some extra logic that we already run to have latest always in sync.
1 parent ed6ad62 commit c7c96de

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

readthedocs/projects/forms.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ class ProjectTriggerBuildMixin:
145145
"""
146146
Mixin to trigger build on form save.
147147
148-
We trigger a build to the default branch and the LATEST version of the project,
149-
since both are related, latest is an alias of the default version.
148+
We trigger a build to LATEST version of the project, and the version
149+
that LATEST points to, since latest is just an alias.
150150
151151
This should be replaced with signals instead of calling trigger_build
152152
explicitly.
@@ -156,11 +156,11 @@ def save(self, commit=True):
156156
"""Trigger build on commit save."""
157157
project = super().save(commit)
158158
if commit:
159-
default_branch = project.versions.filter(slug=project.get_default_branch()).first()
160-
if default_branch and default_branch.active:
161-
trigger_build(project=project, version=default_branch)
159+
original_latest_version = project.get_original_latest_version()
160+
if original_latest_version and original_latest_version.active:
161+
trigger_build(project=project, version=original_latest_version)
162162
latest_version = project.get_latest_version()
163-
if latest_version and latest_version != default_branch and latest_version.active:
163+
if latest_version and latest_version.active:
164164
trigger_build(project=project, version=latest_version)
165165
return project
166166

readthedocs/rtd_tests/tests/test_project_forms.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,16 @@ def test_custom_readthedocs_yaml(self, trigger_build):
300300
@mock.patch("readthedocs.projects.forms.trigger_build")
301301
def test_trigger_build_on_save(self, trigger_build):
302302
latest_version = self.project.get_latest_version()
303-
default_branch = get(Version, project=self.project, slug="main", active=True)
304-
305-
self.project.default_branch = default_branch.slug
303+
default_branch = get(
304+
Version,
305+
project=self.project,
306+
slug="main",
307+
active=True,
308+
type=BRANCH,
309+
verbose_name="main",
310+
identifier="main",
311+
)
312+
self.project.default_branch = default_branch.verbose_name
306313
self.project.save()
307314

308315
data = {

0 commit comments

Comments
 (0)