From 0b3f49fa6d98dbee7483b10886537babf301ef9d Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Fri, 6 Nov 2026 17:26:47 +0900 Subject: [PATCH] Return a Python str from Document.get_type_name() on arcadedb-jvm (closes #286) getTypeName() came back as a java.lang.String on the JVM build and as a str on the native build. The Java string compares equal to a str but does not concatenate with one. Wrap it in str(); the test now asserts type is str on both builds, and the functions-and-events page loses its workaround bullet. Co-Authored-By: Claude Sonnet 5.5 --- docs/modules/ROOT/pages/how-to/functions-and-events.adoc | 3 +-- src/arcadedb/graph.py | 2 +- tests/test_functions_and_events_behavior.py | 9 +++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/docs/modules/ROOT/pages/how-to/functions-and-events.adoc b/docs/modules/ROOT/pages/how-to/functions-and-events.adoc index 0df9935c..b75ceef4 100644 --- a/docs/modules/ROOT/pages/how-to/functions-and-events.adoc +++ b/docs/modules/ROOT/pages/how-to/functions-and-events.adoc @@ -322,7 +322,6 @@ A callback runs inside the operation that fired it, on the thread that runs it. * *Read.* A callback can run `db.query`. A `before_create` callback does not see the new record in a query. An `after_create` callback does. * *Write.* A callback can run `db.command`. The write joins the transaction of the operation that fired the event: it commits with it and rolls back with it. * *Fire more events.* The write of a callback fires events too. A callback registered without `type_name` fires for its own writes. Guard against that, or it never ends. -* *Read the type name with `str(...)`.* On `arcadedb-jvm`, `record.get_type_name()` returns a Java string, not a Python `str`. It compares equal to a `str`, but adding it to a `str`, as in `"created " + record.get_type_name()`, raises `TypeError`. Write `str(record.get_type_name())`. On `arcadedb` it is already a `str`. A property read with `record.get(...)`, a value of `to_dict()` and `get_rid()` are Python `str` on both. * *Change the record.* Do not rely on it. On `arcadedb-jvm` a `before_create` callback can call `record.set(...)`, and the value is stored. On `arcadedb` the change is lost. Put the value in the statement instead. * *Wait.* Keep it quick, and do not wait in it for another thread's transaction. @@ -333,7 +332,7 @@ db.command("sql", "CREATE DOCUMENT TYPE Journal") def note_creation(record): if record.get_type_name() != "Journal": - note = "created " + str(record.get_type_name()) + note = "created " + record.get_type_name() db.command("sql", "INSERT INTO Journal SET note = ?", note) diff --git a/src/arcadedb/graph.py b/src/arcadedb/graph.py index 7feac612..4e3cff6b 100644 --- a/src/arcadedb/graph.py +++ b/src/arcadedb/graph.py @@ -229,7 +229,7 @@ def get_java_document(self): def get_type_name(self) -> str: """Get type name.""" self._check_open() - return self._java_document.getTypeName() + return str(self._java_document.getTypeName()) def __repr__(self) -> str: return ( diff --git a/tests/test_functions_and_events_behavior.py b/tests/test_functions_and_events_behavior.py index 840ad1df..2119c2fc 100644 --- a/tests/test_functions_and_events_behavior.py +++ b/tests/test_functions_and_events_behavior.py @@ -484,11 +484,8 @@ def look(record): for key in ("name", "dict_name", "rid"): assert type(seen[key]) is str, key assert seen["name"] == "x" and seen["dict_name"] == "x" - # the type name is a Java string on the JVM build: it compares equal, and str() makes it a Python str + # the type name is a Python str on both builds, in a callback and outside one value = seen["type_name"] - assert value == "Person" and type(str(value)) is str - assert (type(value) is str) == (arcadedb.__backend__ != "jvm") - # the same holds for a record that is not in a callback + assert value == "Person" and type(value) is str outside = db.query("sql", "SELECT FROM Person").first().get_element() - assert outside.get_type_name() == "Person" - assert (type(outside.get_type_name()) is str) == (arcadedb.__backend__ != "jvm") + assert outside.get_type_name() == "Person" and type(outside.get_type_name()) is str