feat(python-driver): add public API for connection pooling and model dict conversion#2374
Open
uesleilima wants to merge 2 commits intoapache:masterfrom
Open
feat(python-driver): add public API for connection pooling and model dict conversion#2374uesleilima wants to merge 2 commits intoapache:masterfrom
uesleilima wants to merge 2 commits intoapache:masterfrom
Conversation
…dict conversion Add two enhancements to the Python driver's public API: 1. Add configure_connection() function that registers AGE agtype adapters on an existing psycopg connection without creating a new one. This enables use with external connection pools (e.g. psycopg_pool) and managed PostgreSQL services where LOAD 'age' may be restricted. Also explicitly export AgeLoader and ClientCursor as public symbols in age/__init__.py. (apache#2369) 2. Add to_dict() methods to Vertex, Edge, and Path model classes for conversion to plain Python dicts. This enables direct JSON serialization with json.dumps() without requiring custom conversion logic. (apache#2371) - Vertex.to_dict() returns {id, label, properties} - Edge.to_dict() returns {id, label, start_id, end_id, properties} - Path.to_dict() returns a list of to_dict() results Closes apache#2369 Closes apache#2371
…plugins - Replace confusing `skip_load` (double-negative) with `load` (positive boolean, default False). The default now correctly matches the intent: no LOAD by default for connection pool / managed PostgreSQL use cases. - Add `load_from_plugins` parameter for parity with setUpAge(). - Fix docstring to accurately describe parameter behavior. - Add 6 unit tests for configure_connection covering: default no-load, explicit load, load_from_plugins, search_path always set, adapter registration, and graph_name check delegation. Made-with: Cursor
|
@uesleilima thanks a lot for your patch. I let Claude code review run over the patch. Can you please address the issues ? Code ReviewSummaryAdds two useful features to the Python driver: a 🔴 Critical Issues
🟡 Suggestions
✅ What Looks Good
Verdict: Request Changes — The silent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two enhancements to the Python driver's public API:
1. Public API for connection pooling / external connection management (#2369)
The
Ageclass creates and owns a single connection internally. There's no supported way to register agtype adapters on externally-managed connections (e.g., frompsycopg_pool.ConnectionPool).Solution: Add
configure_connection(conn, graph_name=None, skip_load=False)that:search_pathtoag_catalogAgeLoaderLOAD 'age'by default (suitable for managed PostgreSQL services)Also explicitly exports
AgeLoader,ClientCursor, andconfigure_connectionas public symbols inage/__init__.py, eliminating the need for# type: ignorewhen accessing driver internals.Usage with connection pool:
2. Vertex/Edge/Path model classes dict/JSON conversion (#2371)
The driver's model classes lack conversion to plain Python data structures, forcing every consumer to write custom normalization.
Solution: Add
to_dict()methods:Vertex.to_dict()→{"id", "label", "properties"}Edge.to_dict()→{"id", "label", "start_id", "end_id", "properties"}Path.to_dict()→ list ofto_dict()resultsAll return plain dicts/lists that work directly with
json.dumps().Tests
Added 8 new unit tests (no DB required):
TestModelToDict(5 tests): vertex, edge, pathto_dict(), empty properties, JSON serializabilityTestPublicImports(3 tests): verifyconfigure_connection,AgeLoader,ClientCursorare importableCloses