Repository: readthedocs/readthedocs.org

Issue:
Update stable version even when it's inactive
When `stable` is inactive, we don't update it when new versions are created

https://github.com/rtfd/readthedocs.org/blob/3d5ad1ccda5b25ae574e14bedbbf0098c35a6d80/readthedocs/projects/models.py#L714-L714

This leads to `stable` have an old commit/identifier.

When `stable` is activated, we trigger a build but with an old commit, then stable is refreshed and a new build is triggered to stable.

This gives two builds to stable, one to an old commit and one to the _real_ stable.


Any reason why we have this? We even have a test for this https://github.com/rtfd/readthedocs.org/blob/3d5ad1ccda5b25ae574e14bedbbf0098c35a6d80/readthedocs/rtd_tests/tests/test_sync_versions.py#L946

The only "downside" I can see is this, but not sure what would happen. I'll try to see this locally

https://github.com/rtfd/readthedocs.org/blob/3d5ad1ccda5b25ae574e14bedbbf0098c35a6d80/readthedocs/builds/models.py#L209-L210


Discussion:
If "update stable even when inactive" means to update the identifier, I think we should do it since it doesn't affect anything and will make it be consistent with the real stable once activated.

Resolving patch:
diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py
--- a/readthedocs/projects/models.py
+++ b/readthedocs/projects/models.py
@@ -918,7 +918,7 @@ def update_stable_version(self):
                 identifier_updated = (
                     new_stable.identifier != current_stable.identifier
                 )
-                if identifier_updated and current_stable.active and current_stable.machine:
+                if identifier_updated and current_stable.machine:
                     log.info(
                         'Update stable version: {project}:{version}'.format(
                             project=self.slug,
diff --git a/readthedocs/restapi/views/model_views.py b/readthedocs/restapi/views/model_views.py
--- a/readthedocs/restapi/views/model_views.py
+++ b/readthedocs/restapi/views/model_views.py
@@ -216,8 +216,8 @@ def sync_versions(self, request, **kwargs):  # noqa: D205
             )
 
         promoted_version = project.update_stable_version()
-        if promoted_version:
-            new_stable = project.get_stable_version()
+        new_stable = project.get_stable_version()
+        if promoted_version and new_stable and new_stable.active:
             log.info(
                 'Triggering new stable build: {project}:{version}'.format(
                     project=project.slug,


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_sync_versions.py b/readthedocs/rtd_tests/tests/test_sync_versions.py
--- a/readthedocs/rtd_tests/tests/test_sync_versions.py
+++ b/readthedocs/rtd_tests/tests/test_sync_versions.py
@@ -967,9 +967,11 @@ def test_update_inactive_stable_version(self):
             content_type='application/json',
         )
 
+        # The identifier of stable is updated
+        # but the version is still not active
         version_stable = Version.objects.get(slug=STABLE)
         self.assertFalse(version_stable.active)
-        self.assertEqual(version_stable.identifier, '0.9')
+        self.assertEqual(version_stable.identifier, '1.0.0')
 
     def test_stable_version_tags_over_branches(self):
         version_post_data = {