Skip to content

Wait for sync upon graph creation #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2025
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
25 changes: 20 additions & 5 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from arango.cluster import Cluster
from arango.collection import StandardCollection
from arango.connection import Connection
from arango.errno import HTTP_NOT_FOUND
from arango.exceptions import (
AnalyzerCreateError,
AnalyzerDeleteError,
Expand Down Expand Up @@ -1644,12 +1645,14 @@ def has_graph(self, name: str) -> Result[bool]:
:return: True if graph exists, False otherwise.
:rtype: bool
"""
request = Request(method="get", endpoint="/_api/gharial")
request = Request(method="get", endpoint=f"/_api/gharial/{name}")

def response_handler(resp: Response) -> bool:
if not resp.is_success:
raise GraphListError(resp, request)
return any(name == graph["_key"] for graph in resp.body["graphs"])
if resp.is_success:
return True
if resp.status_code == HTTP_NOT_FOUND:
return False
raise GraphListError(resp, request)

return self._execute(request, response_handler)

Expand Down Expand Up @@ -1699,6 +1702,7 @@ def create_graph(
replication_factor: Optional[int] = None,
write_concern: Optional[int] = None,
satellite_collections: Optional[Sequence[str]] = None,
sync: Optional[bool] = None,
) -> Result[Graph]:
"""Create a new graph.

Expand Down Expand Up @@ -1753,6 +1757,8 @@ def create_graph(
element must be a string and a valid collection name. The
collection type cannot be modified later.
:type satellite_collections: [str] | None
:param sync: Wait until everything is synced to disk.
:type sync: bool | None
:return: Graph API wrapper.
:rtype: arango.graph.Graph
:raise arango.exceptions.GraphCreateError: If create fails.
Expand Down Expand Up @@ -1796,7 +1802,16 @@ def create_graph(
if satellite_collections is not None: # pragma: no cover
data["options"]["satellites"] = satellite_collections

request = Request(method="post", endpoint="/_api/gharial", data=data)
params: Params = {}
if sync is not None:
params["waitForSync"] = sync

request = Request(
method="post",
endpoint="/_api/gharial",
data=data,
params=params,
)

def response_handler(resp: Response) -> Graph:
if resp.is_success:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_graph_properties(graph, bad_graph, db):
bad_graph.properties()

new_graph_name = generate_graph_name()
new_graph = db.create_graph(new_graph_name)
new_graph = db.create_graph(new_graph_name, sync=True)
properties = new_graph.properties()
assert properties["id"] == f"_graphs/{new_graph_name}"
assert properties["name"] == new_graph_name
Expand Down
Loading