Skip to content

Commit ce927c7

Browse files
committed
auto parse dict inputs
1 parent 2f4d486 commit ce927c7

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

patchwork/common/utils/input_parsing.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import annotations
22

3+
import json
34
from collections.abc import Iterable, Mapping
5+
from shutil import posix
46

57
from typing_extensions import AnyStr, Union
68

@@ -69,3 +71,22 @@ def parse_to_list(
6971
continue
7072
rv.append(stripped_value)
7173
return rv
74+
75+
def parse_to_dict(possible_dict, limit = -1):
76+
if possible_dict is None and limit == 0:
77+
return None
78+
79+
if isinstance(possible_dict, dict):
80+
new_dict = dict()
81+
for k, v in possible_dict.items():
82+
new_dict[k] = parse_to_dict(v, limit - 1)
83+
return new_dict
84+
elif isinstance(possible_dict, str):
85+
try:
86+
new_dict = json.loads(possible_dict, strict=False)
87+
except json.JSONDecodeError:
88+
return possible_dict
89+
90+
return parse_to_dict(new_dict, limit - 1)
91+
else:
92+
return possible_dict

patchwork/steps/CallSQL/CallSQL.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from sqlalchemy import URL, create_engine, exc, text
44

5+
from patchwork.common.utils.input_parsing import parse_to_dict
56
from patchwork.common.utils.utils import mustache_render
67
from patchwork.logger import logger
78
from patchwork.step import Step, StepStatus
@@ -25,7 +26,7 @@ def __build_engine(self, inputs: dict):
2526
port=inputs.get("db_port", 5432),
2627
password=inputs.get("db_password"),
2728
database=inputs.get("db_database"),
28-
query=inputs.get("db_params"),
29+
query=parse_to_dict(inputs.get("db_params")),
2930
)
3031
connection_url = URL.create(
3132
dialect_plus_driver,
@@ -34,7 +35,7 @@ def __build_engine(self, inputs: dict):
3435

3536
connect_args = None
3637
if inputs.get("db_driver_args") is not None:
37-
connect_args = inputs.get("db_driver_args")
38+
connect_args = parse_to_dict(inputs.get("db_driver_args"))
3839

3940
self.engine = create_engine(connection_url, connect_args=connect_args)
4041
with self.engine.connect() as conn:

patchwork/steps/ModifyCodeOnce/typed.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ class ModifyCodeOnceOutputs(TypedDict):
1515
path: str
1616
start_line: int
1717
end_line: int
18+
diff: str

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "patchwork-cli"
3-
version = "0.0.91.dev0"
3+
version = "0.0.92.dev0"
44
description = ""
55
authors = ["patched.codes"]
66
license = "AGPL"

0 commit comments

Comments
 (0)