Skip to content

Commit

Permalink
Version sync: restore verbose_name for stable version (#11941)
Browse files Browse the repository at this point in the history
Closes #11939

This also discovered another problem, we are using the verbose name to
check for latest/stable, but we should use the slug


https://github.com/readthedocs/readthedocs.org/blob/10d9ef95736b3106b4c5c551df57dda8ed1000e2/readthedocs/vcs_support/backends/git.py#L135-L145

Will try to fix that in another PR, as we need to pass the slug down...
  • Loading branch information
stsewd authored Jan 27, 2025
1 parent 5f3f199 commit e5c3714
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
LATEST,
LATEST_VERBOSE_NAME,
STABLE,
STABLE_VERBOSE_NAME,
)
from readthedocs.core.history import ExtraHistoricalRecords
from readthedocs.core.resolver import Resolver
Expand Down Expand Up @@ -1200,6 +1201,7 @@ def update_stable_version(self):
version_updated = (
new_stable.identifier != current_stable.identifier
or new_stable.type != current_stable.type
or current_stable.verbose_name != STABLE_VERBOSE_NAME
)
if version_updated:
log.info(
Expand All @@ -1209,6 +1211,7 @@ def update_stable_version(self):
version_type=new_stable.type,
)
current_stable.identifier = new_stable.identifier
current_stable.verbose_name = STABLE_VERBOSE_NAME
current_stable.type = new_stable.type
current_stable.save()
return new_stable
Expand Down
49 changes: 49 additions & 0 deletions readthedocs/rtd_tests/tests/test_sync_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,55 @@ def test_machine_attr_when_user_define_stable_branch_and_delete_it_new_project(
)
self.assertTrue(current_stable.machine)

def test_restore_machine_stable_verbose_name(self):
"""
The user imports a new project with a branch named ``Stable``, when
syncing the versions, the RTD's ``stable`` is lost (set to machine=False)
and doesn't update automatically anymore, when the branch
is deleted on the user repository, the RTD's ``stable`` is back
(set to machine=True, and with the correct name in lowercase).
"""
self.pip.versions.exclude(slug="master").delete()
current_stable = self.pip.get_stable_version()
assert current_stable is None

custom_stable = get(
Version,
project=self.pip,
identifier="Stable",
verbose_name="Stable",
slug="stable",
type=BRANCH,
machine=False,
active=True,
)
self.pip.update_stable_version()

assert self.pip.get_stable_version() == custom_stable

branches_data = [
{
"identifier": "master",
"verbose_name": "master",
},
{
"identifier": "0.8.3",
"verbose_name": "0.8.3",
},
]

sync_versions_task(
self.pip.pk,
branches_data=branches_data,
tags_data=[],
)

# RTD stable is restored correctly.
current_stable = self.pip.get_stable_version()
assert current_stable.identifier == "0.8.3"
assert current_stable.verbose_name == "stable"
assert current_stable.machine

def test_machine_attr_when_user_define_latest_tag_and_delete_it(self):
"""The user creates a tag named ``latest`` on an existing repo, when
syncing the versions, the RTD's ``latest`` is lost (set to
Expand Down

0 comments on commit e5c3714

Please sign in to comment.