Skip to content

Commit d7ac416

Browse files
committed
fix: process results
1 parent 53c01c6 commit d7ac416

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

eox_core/api/data/data_collector/tasks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
from celery import shared_task, Task
7-
from eox_core.api.data.data_collector.utils import execute_query, post_data_to_api, serialize_data
7+
from eox_core.api.data.data_collector.utils import execute_query, post_data_to_api, serialize_data, process_query_results
88
import yaml
99
import logging
1010

@@ -59,7 +59,8 @@ def generate_report(self, destination_url, query_file_content, token_generation_
5959
result = execute_query(query_sql)
6060

6161
serialized_result = serialize_data(result)
62-
report_data[query_name] = serialized_result
62+
processed_result = process_query_results(serialized_result)
63+
report_data[query_name] = processed_result
6364
except Exception as e:
6465
logger.error(f"Failed to execute query '{query_name}': {e}")
6566
continue

eox_core/api/data/data_collector/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ def serialize_data(data):
5656
return data
5757

5858

59+
def process_query_results(raw_result):
60+
"""
61+
Process the raw result of a query.
62+
63+
Args:
64+
raw_result: The result from the SQL query (list, scalar, or dictionary).
65+
66+
Returns:
67+
The processed result, extracting scalar values from single-item lists,
68+
or returning the original value for more complex data structures.
69+
"""
70+
if isinstance(raw_result, list) and len(raw_result) == 1:
71+
return raw_result[0]
72+
return raw_result
73+
74+
5975
def post_data_to_api(api_url, report_data, token_generation_url, current_host):
6076
"""
6177
Sends the generated report data to the Shipyard API.

0 commit comments

Comments
 (0)