Skip to content

Ensure proper connection handling in reset_database function#33

Merged
jexp merged 3 commits into
neo4j-labs:mainfrom
unshDee:main
May 11, 2026
Merged

Ensure proper connection handling in reset_database function#33
jexp merged 3 commits into
neo4j-labs:mainfrom
unshDee:main

Conversation

@unshDee

@unshDee unshDee commented May 10, 2026

Copy link
Copy Markdown
Contributor

Problem

make reset fails with:

RuntimeError: Neo4j not connected. Call connect_neo4j() first.

reset_database() in the generated context_graph_client.py called
execute_cypher() directly without initializing the driver first.

Fix

Wrap the DELETE query with connect_neo4j() / close_neo4j() in a
try/finally block — same pattern used elsewhere in the codebase.

Change

templates/backend/shared/context_graph_client.py.j2 — 4-line change
in reset_database().

Fixes #26

Copilot AI review requested due to automatic review settings May 10, 2026 10:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the backend template’s generated reset_database() helper to ensure it establishes a Neo4j connection before executing the destructive DETACH DELETE query, addressing failures in make reset where the driver was never initialized.

Changes:

  • Wrap the reset Cypher execution in connect_neo4j() / close_neo4j() with a try/finally to guarantee cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/create_context_graph/templates/backend/shared/context_graph_client.py.j2 Outdated
Comment thread src/create_context_graph/templates/backend/shared/context_graph_client.py.j2 Outdated
unshDee and others added 2 commits May 11, 2026 07:09
…o4j-labs#26)

Verifies that reset_database() opens its own connection when _driver is
None, closes it via try/finally, preserves pre-existing connections, and
uses MATCH (n) DETACH DELETE n.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jexp jexp merged commit 5409fb0 into neo4j-labs:main May 11, 2026
4 checks passed
@johnymontana johnymontana mentioned this pull request May 18, 2026
akkonrad pushed a commit to akkonrad/create-context-graph that referenced this pull request May 21, 2026
- Add local-file document connector (PR neo4j-labs#34): deterministic ingestion
  of Markdown / PDF / HTML / AsciiDoc / Word into :Document → :Section
  hierarchies with LINKS_TO edges, 8 new optional deps in connectors
  extra, 1,721-line test_local_file_connector.py.
- Fix reset_database() connection lifecycle in generated
  context_graph_client.py (PR neo4j-labs#33) — opens/closes its own driver when
  none is pre-existing.
- Bump pyproject.toml and npm-wrapper/package.json to 0.10.0.
- Refresh CLAUDE.md status, connector count (12 → 13), and test count.
- Remove 4 unused datetime/timezone imports flagged by ruff.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

make reset fails with RuntimeError: Neo4j not connected

3 participants