Skip to content

Docs: Python functions and record events, with tests that pin each statement first (refs #267) - #284

Merged
tae898 merged 2 commits into
mainfrom
docs/functions-events
Nov 6, 2026
Merged

tae898 merged 2 commits into
mainfrom
docs/functions-events

Conversation

@tae898

@tae898 tae898 commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #267 (row 8). Adds the page how-to/functions-and-events.adoc (Python functions in SQL and openCypher, and db.on record events), one nav line, and links from the quickstart, installation, databases-and-queries and transactions pages (one added anchor, failed-statement, on the transactions page).

The existing tests (test_python_callbacks.py, test_native_udf.py, test_python_function_interrupt.py) already pin the basics, so the page header links to them and tests/test_functions_and_events_behavior.py pins only what the page adds: the Python types a function receives from a stored value (datetime, date, Decimal, list, map, and a vertex, edge or document as its wrapper), openCypher arguments and results, that a function runs once per row, that a raising function or callback undoes its statement and leaves the transaction going (26.11.1), that a function belongs to the process and an event to one database (and what closing a database drops), which thread runs a function or an event, that a waiting function blocks only its own statement, when an after_* event fires relative to the commit, only False vetoes, the exact-type filter, and what a callback may do (read, write into the same transaction, fire further events, change the record). tests/test_docs_functions_page.py runs every Python block of the page in order and checks the printed output.

CI: the first JVM run found one wrong page statement (get_type_name() is a Java string on arcadedb-jvm; see the surprises); it is fixed, and the JVM test workflow on that head passed (24 of 24 jobs). The head was then rebased onto main after #282 and its run is in progress; the native parity legs run now that the PR is ready. I could not run pytest on the laptop (a guard blocks it), so the native-side expectations are first observed by CI. Issue #286 tracks the get_type_name() inconsistency; a fix PR follows after this one merges.

Surprises, none filed:

  • A before_create callback that calls record.set(...) changes what is stored on arcadedb-jvm (the callback holds the engine's mutable record) and has no effect on arcadedb (it holds a snapshot dict built in NativeExtras.appendRecord, and only the veto flag goes back). The test pins both and the page says not to rely on it.
  • On arcadedb, a before_update callback gets a record with an RID, which the native wrapper treats as read-only, so record.set(...) there raises instead of being ignored (read from _native/records.py, not tested).
  • register_function says the GIL serializes the calls and fn does not run in parallel. That holds only while fn holds the GIL: a function that waits (sleep, Event, I/O) lets other statements run, and a free-threaded build has no GIL. The page says to write fn as if two threads could call it at once.
  • record.get_type_name() returns a Java string on arcadedb-jvm (graph.py returns getTypeName() unconverted) and a Python str on arcadedb. It compares equal to a str, but "created " + record.get_type_name() raises TypeError on the JVM build only; the first JVM run caught it in a page block. record.get(...), to_dict() values and get_rid() are str on both. The page says to use str(record.get_type_name()), and a test pins the type per backend, inside a callback and outside one.

What remains of #267 after this: rows 4 and 5 (PR #282), row 7, rows 10 and 11 (another agent), and 1, 6, 13 and the stale items under #264.

🤖 Generated with Claude Code

tae898 and others added 2 commits November 6, 2026 16:05
…each statement first (refs #267)

Row 8 of the docs audit: register_function and db.on were only in example 28.
The existing tests already pin the basics (names, argument counts, return
types, a failing function, each event, the veto), so the new behavior tests
pin what the page adds: what a function receives from a stored value (datetime,
date, Decimal, vertex, edge, document), that a raising function or callback
undoes its statement and leaves the transaction going (26.11.1), that a function
belongs to the process and an event to one database, which thread runs a
function or an event (caller, engine thread for async writes), that a waiting
function blocks only its own statement, when an after event fires relative to
the commit, and what a callback may do (read, write into the same transaction,
fire further events, change the record). A docs-page test runs every Python
block in order and checks the printed output.

The tests were written from the sources without a local run (the guard hook
blocks pytest); CI is the first run on both backends.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…onverts it with str() (refs #267)

The JVM run of the docs-page test failed in the Journal block: record.get_type_name()
returns the Java string on arcadedb-jvm (graph.py returns getTypeName() as is), and
"created " + java_string raises TypeError, while the native wrapper returns a str.
record.get(...), to_dict() values and get_rid() are Python str on both builds.
New behavior test pins the type per backend, inside a callback and outside one;
the page says once, in the callback section, to write str(record.get_type_name()),
and the block does.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tae898
tae898 force-pushed the docs/functions-events branch from ca2c583 to e11394a Compare November 6, 2026 07:05
@tae898
tae898 marked this pull request as ready for review November 6, 2026 07:08
@tae898
tae898 merged commit 361e36e into main Nov 6, 2026
82 checks passed
@tae898
tae898 deleted the docs/functions-events branch November 6, 2026 08:25
@github-actions github-actions Bot added this to the 26.12.1 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant