Catch polypheny.Error to handle connector and Prism errors. The exception text for Prism errors comes from the server. The connector exposes the DB-API exception hierarchy, while server errors currently use the base Error class, including errors caused by invalid SQL, constraint violations or authentication.
Exception hierarchy
| Class | Base class | Meaning |
|---|---|---|
Warning |
Exception |
DB-API warning class. |
Error |
Exception |
Base connector error, including server errors and an incompatible Prism handshake. |
InterfaceError |
Error |
DB-API category for interface errors. |
DatabaseError |
Error |
Base DB-API category for database errors. |
DataError |
DatabaseError |
DB-API category for invalid data values. |
OperationalError |
DatabaseError |
DB-API category for failures in database operation. |
IntegrityError |
DatabaseError |
DB-API category for integrity constraint violations. |
InternalError |
DatabaseError |
DB-API category for internal database failures. |
ProgrammingError |
DatabaseError |
Raised for operations such as fetching before execution or calling cursor() on a closed connection. |
NotSupportedError |
DatabaseError |
DB-API category for unsupported database operations. |
Socket failures can surface as OSError or EOFError. Unsupported Python parameter types can raise the built-in NotImplementedError. A failed version check reports both the client and server Prism versions. Verify the server Prism interface and listener configuration when troubleshooting a connection. Mixed graph and scalar projections require a Prism 2.3 server. Cypher and Graph Results
Roll back after a failed statement
This example deliberately queries a table with a generated name that does not exist. The handler rolls back the failed transaction and uses the same connection for a subsequent query. An application that cannot recover should close the connection and report the failure.
import os
from uuid import uuid4
import polypheny
connection = polypheny.connect(
(os.getenv("POLYPHENY_HOST", "127.0.0.1"), int(os.getenv("POLYPHENY_PORT", "20590"))),
username=os.getenv("POLYPHENY_USER", "pa"),
password=os.getenv("POLYPHENY_PASSWORD", ""),
transport="plain",
)
cursor = connection.cursor()
try:
missing_table = f"py_missing_{uuid4().hex[:12]}"
try:
cursor.execute(f"SELECT * FROM {missing_table}")
except polypheny.Error as exc:
connection.rollback()
print(f"Query failed: {exc}")
cursor.execute("SELECT 1")
print(cursor.fetchone())
finally:
connection.close()