Skip to content

Commit

Permalink
fix: fix for dangerous indexing (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
sg-s authored Dec 2, 2024
1 parent 88901f5 commit 3f24273
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ client="mock"
chosen_tests=""
responses="pass"

test:
check-dangerous-indexing:
bash tests/check-dangerous-index.sh


test: check-dangerous-indexing
ifeq ($(client), "mock")
$(eval n_workers=1)
else
Expand Down
2 changes: 1 addition & 1 deletion src/data_hub/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ def row_to_dict(
for field in fields:
if "systemType" in field.keys() and field.systemType == "bodyDocument":
continue
if field.value is None:
if getattr(field, "value", None) is None:
value = None
elif field.type in ["float", "integer", "boolean"]:
value = field.value
Expand Down
11 changes: 11 additions & 0 deletions tests/check-dangerous-index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Search for the pattern and count the matches
if [ "$(grep -rE 'if [a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]* is None:' src | wc -l)" -gt 0 ]; then
echo "foo.bar is None pattern found! Replace with \`if getattr(foo, 'bar', None) is None:\`"
grep -rE 'if [a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]* is None:' src
exit 1
else
echo "No matches found."
exit 0
fi
2 changes: 2 additions & 0 deletions tests/test_cli_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def test_list(config, list_option, json_option): # noqa: F811

@pytest.mark.parametrize("json_option", JSON_OPTIONS)
def test_show_db(config, json_option): # noqa: F811
print(config["databases"][0])

stdout = _run_cli_command(
["data", "show", config["databases"][0]] + json_option,
client=config["client"],
Expand Down

0 comments on commit 3f24273

Please sign in to comment.