From 3c2a35100ec50cea4c89418275524c7174314f6e Mon Sep 17 00:00:00 2001 From: francisco Date: Thu, 6 Mar 2025 15:24:34 -0300 Subject: [PATCH] fix: server error in test of microsoft origin - environment misc platform is null for the test Close #1040 --- backend/kernelCI_app/queries/test.py | 34 ++++++++++--------- backend/kernelCI_app/typeModels/databases.py | 2 +- backend/kernelCI_app/views/testDetailsView.py | 4 ++- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/backend/kernelCI_app/queries/test.py b/backend/kernelCI_app/queries/test.py index 7c506d48..996c87f6 100644 --- a/backend/kernelCI_app/queries/test.py +++ b/backend/kernelCI_app/queries/test.py @@ -42,20 +42,22 @@ def get_test_status_history( platform: str, current_test_timestamp: datetime, ): - return ( - Tests.objects.values( - "field_timestamp", - "id", - "status", - "build__checkout__git_commit_hash", - ) - .filter( - path=path, - build__checkout__origin=origin, - build__checkout__git_repository_url=git_repository_url, - build__checkout__git_repository_branch=git_repository_branch, - environment_misc__platform=platform, - field_timestamp__lte=current_test_timestamp, - ) - .order_by("-field_timestamp")[:10] + query = Tests.objects.values( + "field_timestamp", + "id", + "status", + "build__checkout__git_commit_hash", + ).filter( + path=path, + build__checkout__origin=origin, + build__checkout__git_repository_url=git_repository_url, + build__checkout__git_repository_branch=git_repository_branch, + field_timestamp__lte=current_test_timestamp, ) + + if platform is None: + query = query.filter(environment_misc__platform__isnull=True) + else: + query = query.filter(environment_misc__platform=platform) + + return query.order_by("-field_timestamp")[:10] diff --git a/backend/kernelCI_app/typeModels/databases.py b/backend/kernelCI_app/typeModels/databases.py index 175463cd..0ccb3c87 100644 --- a/backend/kernelCI_app/typeModels/databases.py +++ b/backend/kernelCI_app/typeModels/databases.py @@ -54,7 +54,7 @@ class EnvironmentMisc(BaseModel): type Test__Path = Optional[str] type Test__StartTime = Optional[datetime] type Test__EnvironmentCompatible = Optional[List[str]] -type Test__EnvironmentMisc = Optional[EnvironmentMisc] +type Test__EnvironmentMisc = Optional[Jsonb] type Test__LogExcerpt = Optional[str] type Test__LogUrl = Optional[str] type Test__Misc = Optional[Jsonb] diff --git a/backend/kernelCI_app/views/testDetailsView.py b/backend/kernelCI_app/views/testDetailsView.py index 43fdc18b..596fe94a 100644 --- a/backend/kernelCI_app/views/testDetailsView.py +++ b/backend/kernelCI_app/views/testDetailsView.py @@ -62,12 +62,14 @@ def get(self, _request, test_id: str) -> Response: error_message="Test not found", status_code=HTTPStatus.OK ) + platform = response["environment_misc"].get("platform") + status_history_response = get_test_status_history( path=response["path"], origin=response["build__checkout__origin"], git_repository_url=response["build__checkout__git_repository_url"], git_repository_branch=response["build__checkout__git_repository_branch"], - platform=response["environment_misc"]["platform"], + platform=platform, current_test_timestamp=response["field_timestamp"], )