Repository navigation
Inside the transaction that ran insert_many, a list property reads back as a Java JSONArray instead of a list #112
Description
Level: bindings (Java bridge). After Database.insert_many, a read in the same transaction returns the Java com.arcadedb.serializer.json.JSONArray object for every list property, and for every list nested in a dict, where Document.set and an INSERT statement return a Python list. After the commit the same rows read back as lists. A program that calls insert_many and then reads the rows back before it commits gets Java objects that to_dict(), to_list(), and json.dumps cannot use.
Repro
The script prints to stdout. The JVM's own log lines go to stderr and are discarded by the command below.
uv venv .venv
uv pip install --python .venv/bin/python arcadedb_embedded-26.10.1.dev0-cp312-cp312-manylinux_2_34_x86_64.whl
.venv/bin/python repro-5-insert-many-java-objects-in-transaction.py 2>/dev/null"""Inside the transaction that ran insert_many, a list or a nested map reads back as a Java JSONArray, not a list."""
import os
import tempfile
import arcadedb_embedded as arcade
from arcadedb_embedded.jvm import start_jvm
start_jvm(heap_size="2g")
db = arcade.create_database(os.path.join(tempfile.mkdtemp(prefix="hb5-"), "db"))
db.command("sql", "CREATE DOCUMENT TYPE D")
row = {"tags": ["a", "b"], "nested": {"scores": [1, 2, 3]}, "plain": 7}
with db.transaction():
db.insert_many("D", [row])
d = db.query("sql", "SELECT FROM D").first().to_dict()
print("inside the transaction, insert_many :", d)
print(" type(tags) =", type(d["tags"]).__name__)
db.command("sql", "INSERT INTO D SET tags = ?, nested = ?, plain = 7", row["tags"], row["nested"])
d2 = db.query("sql", "SELECT FROM D WHERE tags IS NOT NULL ORDER BY @rid DESC").first().to_dict()
print("inside the transaction, INSERT SQL :", d2)
print("after the commit, insert_many :", db.query("sql", "SELECT FROM D").to_list()[0])
db.close()Output
Wheel arcadedb_embedded-26.10.1.dev0-cp312-cp312-manylinux_2_34_x86_64.whl with its bundled JRE (OpenJDK 25.0.4.1), JPype 1.7.1, and Python 3.12.13. The engine build the wheel reports through com.arcadedb.Constants is 26.10.1-SNAPSHOT (build 04bb03ebec07fce19101595d65ca1e3bdf516755), an ancestor of upstream cecb369df9. The repository is at f92ac1381c8335249a6fde644cbf04594f6d6391, and the installed Python sources are identical to bindings/python/src/arcadedb_embedded/ at that commit.
inside the transaction, insert_many : {'tags': <java object 'com.arcadedb.serializer.json.JSONArray'>, 'nested': {'scores': <java object 'com.arcadedb.serializer.json.JSONArray'>}, 'plain': 7}
type(tags) = com.arcadedb.serializer.json.JSONArray
inside the transaction, INSERT SQL : {'tags': ['a', 'b'], 'nested': {'scores': [1, 2, 3]}, 'plain': 7}
after the commit, insert_many : {'tags': ['a', 'b'], 'nested': {'scores': [1, 2, 3]}, 'plain': 7}
Cause
DocumentBatcher.fill stores row.get(key) straight into the document (DocumentBatcher.java L123-L126). For a JSON array that value is a JSONArray: the read inside the transaction returns that same object, and the read after the commit returns a list deserialized from the page. The bindings' convert_java_to_python does not know the class, so it returns it unchanged (type_conversion.py L436-L441).
Expected
The rows read back as lists and dicts before and after the commit, as they do for Document.set and for SQL.
Proposed fix
Convert the parsed row to plain Java collections before storing it. JSONObject.toMap() converts nested objects and arrays to Map and List (JSONObject.java L465-L498). This is a sketch, not compiled or applied:
private static void fill(final MutableDocument doc, final JSONObject row) {
- for (final String key : row.keySet())
- doc.set(key, row.isNull(key) ? null : row.get(key));
+ for (final java.util.Map.Entry<String, Object> entry : row.toMap().entrySet())
+ doc.set(entry.getKey(), entry.getValue());
}Related issues
ArcadeData#7882 and its fix, PR ArcadeData#8828 (merged 2026-10-03T09:54Z), touch DocumentBatcher.insertManyJson for transaction hygiene and do not change fill. Nothing else found.
In this repository's tracker no issue is about this. The search for insert_many found only #14 (closed), about create_record error callbacks.
Activity
fix(#112, #116): insert_many stores plain lists, to_json_list writes …
benchmarks: the instrument changes for the 26.10.1 re-pin campaign, w…