Skip to content

Commit

Permalink
Detect and remove NULL/NONE in ssoCards (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmahlke committed Apr 15, 2024
1 parent 6ca9e95 commit c46402d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.9.8
- Detect and remove "Null" and "None" values in ssoCards

# 1.9.7 - 2024-03-01
- Drop support for python3.7
- 'sso_number' column in BFT is now of type Int64
Expand Down
29 changes: 29 additions & 0 deletions rocks/ssodnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,33 @@ async def _query_ssodnet(id_ssodnet, session):
def _postprocess_ssocard(card):
"""Apply ssoCard structure improvements for pydantic deserialization."""

def remove_nulls(d):
"""Overwrite 'NULL' and other values"""

VALUES_TO_REMOVE = ["NULL", "null", "None", "none", ""]

# Base case: If d is not a dictionary, return d as it is
if not isinstance(d, dict):
return d

# Create a list to store keys that need to be deleted
keys_to_delete = []

# Iterate through each key-value pair in the dictionary
for key, value in d.items():
# If the value is a dictionary, recursively call the function
if isinstance(value, dict):
d[key] = remove_nulls(value)
# If the value is in the list of values to check, add the key to the list of keys to delete
elif value in VALUES_TO_REMOVE:
keys_to_delete.append(key)

# Delete keys with values that match any value in values_to_check
for key in keys_to_delete:
del d[key]

return d

def make_dict(values):
"""Turn lower-level dict values into dicts."""
for key, value in values.items():
Expand All @@ -190,6 +217,8 @@ def make_dict(values):
values[key] = {"value": value}
return values

card = remove_nulls(card)

# Turn low-level parameters into dictionaries
card["parameters"] = make_dict(card["parameters"])

Expand Down

0 comments on commit c46402d

Please sign in to comment.