Skip to content

Commit c7d9398

Browse files
fix: treeListing sqlite query (#1686)
1 parent c3d0cd8 commit c7d9398

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

backend/kernelCI_app/helpers/trees.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,33 @@ def sanitize_tree(
8787
"skip": checkout["skip_boots"],
8888
}
8989

90-
if isinstance(checkout.get("git_commit_tags"), str):
90+
# Has to check if it's a string because sqlite doesn't support ArrayFields.
91+
# So if the query came from sqlite, it will be a string.
92+
git_commit_tags = checkout.get("git_commit_tags")
93+
if isinstance(git_commit_tags, str):
9194
try:
92-
checkout["git_commit_tags"] = json.loads(checkout["git_commit_tags"])
93-
if not isinstance(checkout["git_commit_tags"], list):
94-
checkout["git_commit_tags"] = []
95-
except json.JSONDecodeError:
95+
checkout["git_commit_tags"] = json.loads(git_commit_tags)
96+
except (TypeError, json.JSONDecodeError):
97+
log_message(
98+
"git_commit_tags could not be decoded for checkout_id %s, tags: %s"
99+
% (checkout["checkout_id"], git_commit_tags),
100+
)
96101
checkout["git_commit_tags"] = []
97102

103+
if not isinstance(checkout["git_commit_tags"], list):
104+
log_message(
105+
"git_commit_tags is not a list for checkout_id %s, tags: %s"
106+
% (checkout["checkout_id"], checkout["git_commit_tags"]),
107+
)
108+
checkout["git_commit_tags"] = []
109+
110+
# The git_commit_tags comes as list[str] on a normal query, but `Checkout` expects list[list[str]].
111+
# This is a workaround, the queries should *always* return a simple list[str]
112+
if checkout["git_commit_tags"] and not isinstance(
113+
checkout["git_commit_tags"][0], list
114+
):
115+
checkout["git_commit_tags"] = [checkout["git_commit_tags"]]
116+
98117
return Checkout(
99118
**checkout,
100119
build_status=build_status,

0 commit comments

Comments
 (0)