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
3 changes: 1 addition & 2 deletions docs/modules/ROOT/pages/how-to/functions-and-events.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion src/arcadedb/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 3 additions & 6 deletions tests/test_functions_and_events_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading