From 9fe6374d92f01ba8d1f01bab8f70067c357cc6e2 Mon Sep 17 00:00:00 2001 From: atsumi Date: Mon, 24 Jul 2023 18:17:50 +0900 Subject: [PATCH 1/3] Fix tuple handling --- data_diff/config.py | 5 +++++ tests/test_config.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/data_diff/config.py b/data_diff/config.py index 3971f0be..cd4fbb96 100644 --- a/data_diff/config.py +++ b/data_diff/config.py @@ -38,6 +38,11 @@ def _apply_config(config: Dict[str, Any], run_name: str, kw: Dict[str, Any]): for index in "12": run_args[index] = {attr: kw.pop(f"{attr}{index}") for attr in ("database", "table")} + # Make sure array fields are decoded as list, since array fields in toml are decoded as list, but TableSegment object requires tuple type. + for field in ["key_columns", "columns"]: + if isinstance(run_args.get(field), list): + run_args[field] = tuple(run_args[field]) + # Process databases + tables for index in "12": try: diff --git a/tests/test_config.py b/tests/test_config.py index fb8a6245..4f331d5e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -15,6 +15,8 @@ def test_basic(self): [run.default] update_column = "timestamp" + key_columns = ["id"] + columns = ["name", "age"] verbose = true threads = 2 @@ -39,6 +41,8 @@ def test_basic(self): assert res["table2"] == "rating_del1" assert res["threads1"] == 11 assert res["threads2"] == 22 + assert res["key_columns"] == ("id",) + assert res["columns"] == ("name","age") res = apply_config_from_string(config, "pg_pg", {"update_column": "foo", "table2": "bar"}) assert res["update_column"] == "foo" From fbaeef184f256d9ac47b47cc4cb6b79db1471dc9 Mon Sep 17 00:00:00 2001 From: atsumi Date: Mon, 24 Jul 2023 18:34:40 +0900 Subject: [PATCH 2/3] use constant --- data_diff/config.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data_diff/config.py b/data_diff/config.py index cd4fbb96..1b091f07 100644 --- a/data_diff/config.py +++ b/data_diff/config.py @@ -4,6 +4,12 @@ import toml +_ARRAY_FIELDS = ( + "key_columns", + "columns", +) + + class ConfigParseError(Exception): pass @@ -39,7 +45,7 @@ def _apply_config(config: Dict[str, Any], run_name: str, kw: Dict[str, Any]): run_args[index] = {attr: kw.pop(f"{attr}{index}") for attr in ("database", "table")} # Make sure array fields are decoded as list, since array fields in toml are decoded as list, but TableSegment object requires tuple type. - for field in ["key_columns", "columns"]: + for field in _ARRAY_FIELDS: if isinstance(run_args.get(field), list): run_args[field] = tuple(run_args[field]) From 2a785614d0a5f804b6795e0643d7b9f92ae4c966 Mon Sep 17 00:00:00 2001 From: atsumi Date: Mon, 24 Jul 2023 18:37:00 +0900 Subject: [PATCH 3/3] black --- tests/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index 4f331d5e..960ee15d 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -42,7 +42,7 @@ def test_basic(self): assert res["threads1"] == 11 assert res["threads2"] == 22 assert res["key_columns"] == ("id",) - assert res["columns"] == ("name","age") + assert res["columns"] == ("name", "age") res = apply_config_from_string(config, "pg_pg", {"update_column": "foo", "table2": "bar"}) assert res["update_column"] == "foo"