Skip to content

Commit

Permalink
Scan context: support list keys in getter (#2135)
Browse files Browse the repository at this point in the history
  • Loading branch information
m1n0 authored Jul 18, 2024
1 parent 5d3577b commit 4fc27bb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions soda/core/soda/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,10 +960,22 @@ def get_all_checks_text(self) -> str | None:
def has_soda_cloud_connection(self):
return self._configuration.soda_cloud is not None

def scan_context_get(self, key: str, default: any = None) -> any:
return self.scan_context.get(key, default)
def scan_context_get(self, key: str | list[str], default: any = None) -> any:

if type(key) == str:
return self.scan_context.get(key, default)
elif type(key) == list:
nested_dict = self.scan_context
for k in key:
if isinstance(nested_dict, dict) and k in nested_dict:
nested_dict = nested_dict[k]
else:
return default
return nested_dict
else:
raise TypeError("Key must be a string or a list of strings")

def scan_context_set(self, key: str | list, value: any, overwrite: bool = True):
def scan_context_set(self, key: str | list[str], value: any, overwrite: bool = True):
dic = self.scan_context
dic_key = key

Expand Down

0 comments on commit 4fc27bb

Please sign in to comment.