Skip to content

Commit

Permalink
fix: Set early return when influxdb range is empty (#4274)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan authored Jul 9, 2024
1 parent 8d048d8 commit 007351c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/app_analytics/influxdb_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def influx_query_manager(
extra: str = "",
bucket: str = read_bucket,
):
# Influx throws an error for an empty range, so just return a list.
if date_start == "-0d" and date_stop == "now()":
return []

query_api = influxdb_client.query_api()
drop_columns_input = str(list(drop_columns)).replace("'", '"')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,14 @@ def test_get_top_organisations_value_error(
# The wrongly typed data does not stop the remaining data
# from being returned.
assert dataset == {456: 43}


def test_early_return_for_empty_range_for_influx_query_manager() -> None:
# When
results = InfluxDBWrapper.influx_query_manager(
date_start="-0d",
date_stop="now()",
)

# Then
assert results == []

0 comments on commit 007351c

Please sign in to comment.