Skip to content

"Default branch: latest" does not exist Fix. #5547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def __init__(self, *args, **kwargs):
# the special cases of LATEST and STABLE.
all_versions_choices = [
(v.commit_name, v.verbose_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use verbose_name for the id too now (commit_name was used only for the special cases of latest and stable). Also, we should add a test when the user has a version named latest or stable. Using commit_name will make the test fail.

Something like 82944ca

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I'll Update the PR accordingly. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stsewd What did you actually mean by this can you please clarify?

Using commit_name will make the test fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you write a test with a tag named latest or stable the current implementation will fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, a version created by the user machine=False

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stsewd Updated the changes. but I'm Not sure I correctly understood what you meant about the tests. please have a look and let me know.

for v in self.instance.versions.all()
for v in self.instance.versions.filter(machine=False)
]
self.fields['default_branch'].widget = forms.Select(
choices=[default_choice] + all_versions_choices,
Expand Down
12 changes: 9 additions & 3 deletions readthedocs/rtd_tests/tests/test_project_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,26 @@ def test_list_only_active_versions_on_default_version(self):
{'latest', 'public-1', 'public-2', 'private', 'protected'},
)

def test_list_all_versions_on_default_branch(self):
def test_list_only_non_auto_generated_versions_on_default_branch(self):
form = ProjectAdvancedForm(instance=self.project)
# This version is created automatically by the project on save
self.assertTrue(self.project.versions.filter(slug=LATEST).exists())
latest = self.project.versions.filter(slug=LATEST)
self.assertTrue(latest.exists())
self.assertEqual(
{
identifier
for identifier, _ in form.fields['default_branch'].widget.choices
},
{
None, 'master', 'public-1', 'public-2',
None, 'public-1', 'public-2',
'public-3', 'public/4', 'protected', 'private',
},
)
self.assertNotIn(
latest.first().identifier,
[identifier for identifier, _ in form.fields[
'default_branch'].widget.choices],
)

def test_default_version_field_if_no_active_version(self):
project_1 = get(Project)
Expand Down