Skip to content

Commit

Permalink
Merge pull request #165 from stat-kwon/master
Browse files Browse the repository at this point in the history
Change filter when there is a global variable but no value
  • Loading branch information
stat-kwon authored Jan 13, 2025
2 parents a3acbac + 39cb641 commit 137472a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,6 @@ def is_jinja_expression(self, expression: str) -> bool:
def change_global_variables(self, expression: str, vars: dict):
gv_type_map = {}
if "global" in self.jinja_variables:
if not vars:
raise ERROR_NO_FIELDS_TO_GLOBAL_VARIABLES(vars=vars)

exclude_keys = set(key for key in self.jinja_variables if key != "global")
expression = expression.replace("global.", "")

Expand All @@ -297,11 +294,7 @@ def change_global_variables(self, expression: str, vars: dict):
jinja_variables = meta.find_undeclared_variables(parsed_content)

global_variables = jinja_variables - exclude_keys
for global_variable_key in global_variables:
if global_variable_key not in vars:
raise ERROR_NOT_GLOBAL_VARIABLE_KEY(
global_variable_key=global_variable_key
)
for global_variable_key in global_variables and vars:

global_variable_value = vars[global_variable_key]
gv_type = type(global_variable_value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def _make_query(
if self.filter:
for filter_info in self.filter:
query_value = filter_info.get("v") or filter_info.get("value")
query_key = filter_info.get("k") or filter_info.get("key")
if self.is_jinja_expression(query_value):
query_value, gv_type_map = self.change_global_variables(
query_value, vars
Expand All @@ -361,6 +362,9 @@ def _make_query(
elif isinstance(query_value, list):
filter_info["v"] = query_value

if query_key == query_value:
self.filter = None

return {
"granularity": granularity,
"start": start,
Expand Down

0 comments on commit 137472a

Please sign in to comment.