Repository navigation
Description
Both packages: once the engine has started, a relative database path after os.chdir does not name the database in the current directory. A program can fail to find a database it just created, or be refused a second database that is in another directory. I propose that the bindings make a relative path absolute against Python's current directory before the engine sees it.
Reproduce
Two of the tests in #518, which ran against the wheels of a7d444a (two_dirs first opens one database, so that the engine is running, and returns two empty directories):
def test_exists_and_open_or_create_follow_the_current_directory(two_dirs, monkeypatch):
first, second = two_dirs
monkeypatch.chdir(first)
with arcadedb.open_or_create_database("db") as db:
db.command("sql", "CREATE DOCUMENT TYPE InFirst")
assert arcadedb.database_exists("db") # fails: False
def test_one_relative_path_opens_two_databases_from_two_directories(two_dirs, monkeypatch):
first, second = two_dirs
monkeypatch.chdir(first)
with arcadedb.create_database("db") as in_first:
in_first.command("sql", "CREATE DOCUMENT TYPE InFirst")
monkeypatch.chdir(second)
with arcadedb.create_database("db") as in_second: # fails: already in use
...The second error, from the JVM package. The directory it names is the one the engine had started in, not first or second:
arcadedb.exceptions.ArcadeDBError: Failed to create database: com.arcadedb.exception.DatabaseOperationException: Found active instance of database '/home/runner/work/arcadedb-python/arcadedb-python/db' already in use
Results
The same six tests failed on arcadedb-jvm (linux/amd64, Python 3.14) and on arcadedb (linux-x86_64, Python 3.12).
After os.chdir |
Expected | Actual |
|---|---|---|
create a database at ./db, close it |
./db/schema.json exists |
it does not |
open_or_create_database("db"), then database_exists("db") |
True |
False |
a second db from another directory while the first is open |
two databases | Found active instance of database ... already in use |
DatabaseFactory("db"), change directory, create(), exists() |
True |
False |
db.get_database_path() for ./db, after another os.chdir |
an absolute path | ./db |
ArcadeDBServer(root_path="./server_root"), change directory, start |
starts | Error on creating new server event log file ./server_root/log/... (No such file or directory) |
create_server(root_path="./server_root"), the same |
starts | starts (it already makes the root absolute) |
import_documents("rows.csv") and export_database("backup.jsonl.tgz") |
files of the current directory | as expected |
Cause (read from the engine source, not traced in a debugger)
Java reads the working directory once, into user.dir, when it starts. DatabaseFactory.getNormalizedPath (Path.of(path).toAbsolutePath()) and FileManager (new PaginatedComponentFile(f.getAbsolutePath(), mode)) resolve a relative path against that value, while calls such as File.exists() and mkdirs() follow the current directory of the process.
Activity
fix: take a relative database path from Python's current directory