Skip to content

Commit 86b06c4

Browse files
committed
Preserve JSON-like string parameters
1 parent babcafc commit 86b06c4

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

src_cpp/py_connection.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -984,20 +984,6 @@ Value PyConnection::transformPythonValue(const py::handle& val) {
984984
}
985985

986986
Value PyConnection::transformPythonValueFromParameter(const py::handle& val) {
987-
if (py::isinstance<py::str>(val)) {
988-
auto strVal = py::cast<std::string>(val);
989-
if (!strVal.empty() && (strVal.front() == '{' || strVal.front() == '[')) {
990-
auto jsonModule = py::module_::import("json");
991-
try {
992-
auto parsed = jsonModule.attr("loads")(val);
993-
auto parsedType = pyLogicalTypeFromParameter(parsed);
994-
if (parsedType.containsAny()) {
995-
return Value(LogicalType::JSON(), strVal);
996-
}
997-
return transformPythonValueFromParameterAs(parsed, parsedType);
998-
} catch (...) {}
999-
}
1000-
}
1001987
auto type = pyLogicalTypeFromParameter(val);
1002988
return transformPythonValueFromParameterAs(val, type);
1003989
}

test/test_parameter.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ def test_str_param(conn_db_readonly: ConnDB) -> None:
117117
result.close()
118118

119119

120+
def test_json_like_string_param_round_trips_as_string(conn_db_empty: ConnDB) -> None:
121+
conn, _ = conn_db_empty
122+
conn.execute("CREATE NODE TABLE T(id STRING PRIMARY KEY, cfg STRING)")
123+
124+
value = '{"curator_enabled": false, "x": [1, 2, null]}'
125+
result = conn.execute(
126+
"""
127+
CREATE (t:T {id: "a"})
128+
SET t.cfg = $cfg
129+
RETURN t.cfg
130+
""",
131+
{"cfg": value},
132+
)
133+
134+
assert result.get_next() == [value]
135+
assert not result.has_next()
136+
result.close()
137+
138+
120139
def test_date_param(conn_db_readonly: ConnDB) -> None:
121140
conn, _ = conn_db_readonly
122141
result = conn.execute(

0 commit comments

Comments
 (0)