Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src_cpp/py_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,20 +984,6 @@ Value PyConnection::transformPythonValue(const py::handle& val) {
}

Value PyConnection::transformPythonValueFromParameter(const py::handle& val) {
if (py::isinstance<py::str>(val)) {
auto strVal = py::cast<std::string>(val);
if (!strVal.empty() && (strVal.front() == '{' || strVal.front() == '[')) {
auto jsonModule = py::module_::import("json");
try {
auto parsed = jsonModule.attr("loads")(val);
auto parsedType = pyLogicalTypeFromParameter(parsed);
if (parsedType.containsAny()) {
return Value(LogicalType::JSON(), strVal);
}
return transformPythonValueFromParameterAs(parsed, parsedType);
} catch (...) {}
}
}
auto type = pyLogicalTypeFromParameter(val);
return transformPythonValueFromParameterAs(val, type);
}
Expand Down
19 changes: 19 additions & 0 deletions test/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ def test_str_param(conn_db_readonly: ConnDB) -> None:
result.close()


def test_json_like_string_param_round_trips_as_string(conn_db_empty: ConnDB) -> None:
conn, _ = conn_db_empty
conn.execute("CREATE NODE TABLE T(id STRING PRIMARY KEY, cfg STRING)")

value = '{"curator_enabled": false, "x": [1, 2, null]}'
result = conn.execute(
"""
CREATE (t:T {id: "a"})
SET t.cfg = $cfg
RETURN t.cfg
""",
{"cfg": value},
)

assert result.get_next() == [value]
assert not result.has_next()
result.close()


def test_date_param(conn_db_readonly: ConnDB) -> None:
conn, _ = conn_db_readonly
result = conn.execute(
Expand Down
Loading