diff --git a/sqlspec/adapters/aiosqlite/config.py b/sqlspec/adapters/aiosqlite/config.py index 05a891d59..3db737e88 100644 --- a/sqlspec/adapters/aiosqlite/config.py +++ b/sqlspec/adapters/aiosqlite/config.py @@ -78,22 +78,6 @@ async def create_connection(self) -> Connection: msg = f"Could not configure the Aiosqlite connection. Error: {e!s}" raise ImproperConfigurationError(msg) from e - @asynccontextmanager - async def lifespan(self, *args: Any, **kwargs: Any) -> AsyncGenerator[None, None]: - """Manage the lifecycle of a database connection. - - Yields: - None - - Raises: - ImproperConfigurationError: If the connection could not be established. - """ - connection = await self.create_connection() - try: - yield - finally: - await connection.close() - @asynccontextmanager async def provide_connection(self, *args: Any, **kwargs: Any) -> AsyncGenerator[Connection, None]: """Create and provide a database connection. diff --git a/sqlspec/adapters/asyncmy/config.py b/sqlspec/adapters/asyncmy/config.py index e725d164e..bad5e513c 100644 --- a/sqlspec/adapters/asyncmy/config.py +++ b/sqlspec/adapters/asyncmy/config.py @@ -161,23 +161,6 @@ async def provide_pool(self, *args: Any, **kwargs: Any) -> Pool: """ return await self.create_pool() - @asynccontextmanager - async def lifespan(self, *args: Any, **kwargs: Any) -> AsyncGenerator[None, None]: - """Manage the lifecycle of a database connection pool. - - Yields: - None - - Raises: - ImproperConfigurationError: If the pool could not be established. - """ - pool = await self.create_pool() - try: - yield - finally: - pool.close() - await pool.wait_closed() - @asynccontextmanager async def provide_connection(self, *args: Any, **kwargs: Any) -> AsyncGenerator[Connection, None]: """Create and provide a database connection. diff --git a/sqlspec/adapters/asyncpg/config.py b/sqlspec/adapters/asyncpg/config.py index 71a41b2cd..53f82706d 100644 --- a/sqlspec/adapters/asyncpg/config.py +++ b/sqlspec/adapters/asyncpg/config.py @@ -123,15 +123,6 @@ async def create_pool(self) -> Pool: ) return self.pool_instance - @asynccontextmanager - async def lifespan(self, *args: Any, **kwargs: Any) -> AsyncGenerator[None, None]: - db_pool = await self.create_pool() - try: - yield - finally: - db_pool.terminate() - await db_pool.close() - def provide_pool(self, *args: Any, **kwargs: Any) -> Awaitable[Pool]: """Create a pool instance. diff --git a/sqlspec/adapters/duckdb/config.py b/sqlspec/adapters/duckdb/config.py index ee10b8e16..6aeff8fc3 100644 --- a/sqlspec/adapters/duckdb/config.py +++ b/sqlspec/adapters/duckdb/config.py @@ -184,22 +184,6 @@ def create_connection(self) -> DuckDBPyConnection: msg = f"Could not configure the DuckDB connection. Error: {e!s}" raise ImproperConfigurationError(msg) from e - @contextmanager - def lifespan(self, *args: Any, **kwargs: Any) -> Generator[None, None, None]: - """Manage the lifecycle of a database connection. - - Yields: - None - - Raises: - ImproperConfigurationError: If the connection could not be established. - """ - connection = self.create_connection() - try: - yield - finally: - connection.close() - @contextmanager def provide_connection(self, *args: Any, **kwargs: Any) -> Generator[DuckDBPyConnection, None, None]: """Create and provide a database connection. diff --git a/sqlspec/adapters/oracledb/config/_asyncio.py b/sqlspec/adapters/oracledb/config/_asyncio.py index 59dbabf6b..748823c59 100644 --- a/sqlspec/adapters/oracledb/config/_asyncio.py +++ b/sqlspec/adapters/oracledb/config/_asyncio.py @@ -75,14 +75,6 @@ async def create_pool(self) -> AsyncConnectionPool: raise ImproperConfigurationError(msg) return self.pool_instance - @asynccontextmanager - async def lifespan(self, *args: Any, **kwargs: Any) -> AsyncGenerator[None, None]: - db_pool = await self.create_pool() - try: - yield - finally: - await db_pool.close(force=True) - def provide_pool(self, *args: Any, **kwargs: Any) -> Awaitable[AsyncConnectionPool]: """Create a pool instance. diff --git a/sqlspec/adapters/oracledb/config/_sync.py b/sqlspec/adapters/oracledb/config/_sync.py index 069614642..3e9868704 100644 --- a/sqlspec/adapters/oracledb/config/_sync.py +++ b/sqlspec/adapters/oracledb/config/_sync.py @@ -75,13 +75,6 @@ def create_pool(self) -> ConnectionPool: raise ImproperConfigurationError(msg) return self.pool_instance - def lifespan(self, *args: Any, **kwargs: Any) -> Generator[None, None, None]: - db_pool = self.create_pool() - try: - yield - finally: - db_pool.close() - def provide_pool(self, *args: Any, **kwargs: Any) -> ConnectionPool: """Create a pool instance. diff --git a/sqlspec/adapters/psycopg/config/_async.py b/sqlspec/adapters/psycopg/config/_async.py index 76d18e174..2581d3b9c 100644 --- a/sqlspec/adapters/psycopg/config/_async.py +++ b/sqlspec/adapters/psycopg/config/_async.py @@ -63,15 +63,6 @@ async def create_pool(self) -> AsyncConnectionPool: raise ImproperConfigurationError(msg) return self.pool_instance - @asynccontextmanager - async def lifespan(self, *args: Any, **kwargs: Any) -> AsyncGenerator[None, None]: - """Manage the lifecycle of the connection pool.""" - pool = await self.create_pool() - try: - yield - finally: - await pool.close() - def provide_pool(self, *args: Any, **kwargs: Any) -> Awaitable[AsyncConnectionPool]: """Create and return a connection pool.""" return self.create_pool() diff --git a/sqlspec/adapters/psycopg/config/_sync.py b/sqlspec/adapters/psycopg/config/_sync.py index 7136df4fa..70d3499b1 100644 --- a/sqlspec/adapters/psycopg/config/_sync.py +++ b/sqlspec/adapters/psycopg/config/_sync.py @@ -63,15 +63,6 @@ def create_pool(self) -> ConnectionPool: raise ImproperConfigurationError(msg) return self.pool_instance - @contextmanager - def lifespan(self, *args: Any, **kwargs: Any) -> Generator[None, None, None]: - """Manage the lifecycle of the connection pool.""" - pool = self.create_pool() - try: - yield - finally: - pool.close() - def provide_pool(self, *args: Any, **kwargs: Any) -> ConnectionPool: """Create and return a connection pool.""" return self.create_pool() diff --git a/sqlspec/adapters/sqlite/config.py b/sqlspec/adapters/sqlite/config.py index 4b2baea46..1dec9d8a1 100644 --- a/sqlspec/adapters/sqlite/config.py +++ b/sqlspec/adapters/sqlite/config.py @@ -75,22 +75,6 @@ def create_connection(self) -> Connection: msg = f"Could not configure the SQLite connection. Error: {e!s}" raise ImproperConfigurationError(msg) from e - @contextmanager - def lifespan(self, *args: Any, **kwargs: Any) -> Generator[None, None, None]: - """Manage the lifecycle of a database connection. - - Yields: - None - - Raises: - ImproperConfigurationError: If the connection could not be established. - """ - connection = self.create_connection() - try: - yield - finally: - connection.close() - @contextmanager def provide_connection(self, *args: Any, **kwargs: Any) -> Generator[Connection, None, None]: """Create and provide a database connection. diff --git a/tests/unit/test_adapters/test_duckdb/test_config.py b/tests/unit/test_adapters/test_duckdb/test_config.py index 210a2a138..3fd6759cc 100644 --- a/tests/unit/test_adapters/test_duckdb/test_config.py +++ b/tests/unit/test_adapters/test_duckdb/test_config.py @@ -250,19 +250,3 @@ def test_connection_creation_error(self) -> None: config = DuckDBConfig() with pytest.raises(ImproperConfigurationError, match="Could not configure"): config.create_connection() - - def test_connection_lifecycle(self, mock_duckdb_connection: MagicMock) -> None: - """Test connection lifecycle management.""" - config = DuckDBConfig() - - # Test lifespan - with config.lifespan(): - assert mock_duckdb_connection.close.call_count == 0 - assert mock_duckdb_connection.close.call_count == 1 - - # Test provide_connection - mock_duckdb_connection.reset_mock() - with config.provide_connection() as conn: - assert conn is mock_duckdb_connection - assert mock_duckdb_connection.close.call_count == 0 - assert mock_duckdb_connection.close.call_count == 1 diff --git a/uv.lock b/uv.lock index e0a74e40f..0a10ade2a 100644 --- a/uv.lock +++ b/uv.lock @@ -2265,15 +2265,15 @@ wheels = [ [[package]] name = "pyright" -version = "1.1.390" +version = "1.1.391" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "nodeenv" }, { name = "typing-extensions" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/ba/42/1e0392f35dd275f9f775baf7c86407cef7f6a0d9b8e099a93e5422a7e571/pyright-1.1.390.tar.gz", hash = "sha256:aad7f160c49e0fbf8209507a15e17b781f63a86a1facb69ca877c71ef2e9538d", size = 21950 } +sdist = { url = "https://files.pythonhosted.org/packages/11/05/4ea52a8a45cc28897edb485b4102d37cbfd5fce8445d679cdeb62bfad221/pyright-1.1.391.tar.gz", hash = "sha256:66b2d42cdf5c3cbab05f2f4b76e8bec8aa78e679bfa0b6ad7b923d9e027cadb2", size = 21965 } wheels = [ - { url = "https://files.pythonhosted.org/packages/43/20/3f492ca789fb17962ad23619959c7fa642082621751514296c58de3bb801/pyright-1.1.390-py3-none-any.whl", hash = "sha256:ecebfba5b6b50af7c1a44c2ba144ba2ab542c227eb49bc1f16984ff714e0e110", size = 18579 }, + { url = "https://files.pythonhosted.org/packages/ad/89/66f49552fbeb21944c8077d11834b2201514a56fd1b7747ffff9630f1bd9/pyright-1.1.391-py3-none-any.whl", hash = "sha256:54fa186f8b3e8a55a44ebfa842636635688670c6896dcf6cf4a7fc75062f4d15", size = 18579 }, ] [[package]]