Skip to content

API: don't rely on the version object for builds #12395

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion readthedocs/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ class BuildCommandReadOnlySerializer(BuildCommandSerializer):
command = serializers.SerializerMethodField()

def get_command(self, obj):
return normalize_build_command(obj.command, obj.build.project.slug, obj.build.version.slug)
return normalize_build_command(
obj.command, obj.build.project.slug, obj.build.get_version_slug()
)


class BuildSerializer(serializers.ModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/api/v2/views/model_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def retrieve(self, *args, **kwargs):
buildcommand["command"] = normalize_build_command(
buildcommand["command"],
instance.project.slug,
instance.version.slug,
instance.get_version_slug(),
)
except Exception:
log.exception(
Expand Down
23 changes: 23 additions & 0 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,29 @@ def test_build_filter_by_commit(self):
build = resp.data
self.assertEqual(len(build["results"]), 1)

def test_build_without_version(self):
build = get(
Build,
project=self.project,
version=None,
state=BUILD_STATE_FINISHED,
exit_code=0,
)
command = "python -m pip install --upgrade --no-cache-dir pip setuptools<58.3.0"
get(
BuildCommandResult,
build=build,
command=command,
output="Running...",
exit_code=0,
)
client = APIClient()
client.force_authenticate(user=self.user)
r = client.get(reverse("build-detail", args=(build.pk,)))
assert r.status_code == 200
assert r.data["version"] is None
assert r.data["commands"][0]["command"] == command


class APITests(TestCase):
fixtures = ["eric.json", "test_data.json"]
Expand Down