diff --git a/CHANGELOG.md b/CHANGELOG.md index c0fe463f2..a30ad98b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +## [0.4.24] - 2023-12-08 +### Fixed +- `task_utils/get_nested_value` fixed issue with non dict parameter passed without level(1st workflow) + + ## [0.4.23] - 2023-12-07 ### Added - Added tests for new functionalities in SAPRFC and SAPRFCV2 regarding passing credentials. diff --git a/tests/integration/flows/test_sharepoint_to_adls.py b/tests/integration/flows/test_sharepoint_to_adls.py index 198704aa5..eee13ffe6 100644 --- a/tests/integration/flows/test_sharepoint_to_adls.py +++ b/tests/integration/flows/test_sharepoint_to_adls.py @@ -1,6 +1,7 @@ import os from unittest import mock +import logging import pandas as pd import pendulum import pytest @@ -224,7 +225,7 @@ def test_sharepoint_list_to_adls_run_flow_success_on_no_data_returned(mocked_cla ) @pytest.mark.run def test_sharepoint_list_to_adls_run_flow_success_warn_on_no_data_returned( - mocked_class, + mocked_class, caplog ): """ Test will check if flow is failing when empty DF is passed @@ -232,15 +233,17 @@ def test_sharepoint_list_to_adls_run_flow_success_warn_on_no_data_returned( CSV file should not be generated! """ # Get prefect client instance - flow = SharepointListToADLS( - "test_sharepoint_to_adls_run_flow", - output_file_extension=".csv", - adls_sp_credentials_secret=CREDENTIALS_SECRET, - adls_dir_path=ADLS_DIR_PATH, - file_name=ADLS_FILE_NAME_LIST, - list_title="", - site_url="", - if_no_data_returned="warn", - ) - result = flow.run() + with caplog.at_level(logging.WARNING): + flow = SharepointListToADLS( + "test_sharepoint_to_adls_run_flow", + output_file_extension=".csv", + adls_sp_credentials_secret=CREDENTIALS_SECRET, + adls_dir_path=ADLS_DIR_PATH, + file_name=ADLS_FILE_NAME_LIST, + list_title="", + site_url="", + if_no_data_returned="warn", + ) + result = flow.run() + assert "No data in the source response. Df empty." in caplog.text assert result.is_successful() diff --git a/tests/test_viadot.py b/tests/test_viadot.py index 72df7dfca..7493c14f5 100644 --- a/tests/test_viadot.py +++ b/tests/test_viadot.py @@ -2,4 +2,4 @@ def test_version(): - assert __version__ == "0.4.23" + assert __version__ == "0.4.24" diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 38564ed9e..2d6567da8 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -315,3 +315,9 @@ def test_get_nested_value_without_levels(nested_dict): "searched_phrase_3": "Found it!", } assert result_2 == {"searched_phrase_2": "Found it_2!"} + + +def test_get_nested_value_non_dict_passed(): + """Sample test checking the correctness of the function when non dict value (int) is provided.""" + + assert get_nested_value(nested_dict=5) == None diff --git a/viadot/__init__.py b/viadot/__init__.py index c6dd1e2c0..9e6207df0 100644 --- a/viadot/__init__.py +++ b/viadot/__init__.py @@ -1 +1 @@ -__version__ = "0.4.23" +__version__ = "0.4.24" diff --git a/viadot/utils.py b/viadot/utils.py index 654a408d1..0c819ccff 100644 --- a/viadot/utils.py +++ b/viadot/utils.py @@ -491,13 +491,16 @@ def get_nested_value( else: return nested_dict[lvl] else: - for lvl in nested_dict.values(): - if isinstance(lvl, dict): - return get_nested_value(nested_dict=lvl) - else: - return nested_dict + if isinstance(nested_dict, dict): + for lvl in nested_dict.values(): + if isinstance(lvl, dict): + return get_nested_value(nested_dict=lvl) + else: + return nested_dict + else: + return None except KeyError as e: return None - except TypeError as e: + except (TypeError, AttributeError) as e: logger.error(f"The 'nested_dict' must be a dictionary. {e}") return None