Skip to content

Fix issue 2530#3688

Draft
williamacostalora wants to merge 7 commits into
apache:mainfrom
williamacostalora:fix-issue-2530
Draft

Fix issue 2530#3688
williamacostalora wants to merge 7 commits into
apache:mainfrom
williamacostalora:fix-issue-2530

Conversation

@williamacostalora

@williamacostalora williamacostalora commented Jul 20, 2026

Copy link
Copy Markdown

Closes #2530

Rationale for this change

Python 3.13 introduced stricter resource leak detection that flags unclosed
sqlite3 connections left open by SQLAlchemy connection pools after test teardown.
PR #2863 added warning filters in pyproject.toml to suppress these warnings
rather than fixing the root cause. This PR resolves the underlying issue by
adding catalog.close() / engine.dispose() calls to all affected test fixtures
and removes the sqlite ResourceWarning filter.

Nine locations across tests/catalog/test_sql.py and tests/conftest.py created
SqlCatalog instances without calling catalog.close() during teardown. The
close() method (which calls self.engine.dispose()) already existed and was
correctly implemented in pyiceberg/catalog/sql.py — it simply wasn't being
invoked by the fixtures.

Note: The two ray-related warning filters (unclosed file, subprocess still running) are left in place as ray is an optional dependency requiring a CI
environment to reproduce and verify. Happy to address those in a follow-up PR.

Are these changes tested?

Yes. Removed the sqlite ResourceWarning filter from pyproject.toml and ran:
uv run python -m pytest tests/catalog/test_sql.py -W error::ResourceWarning -v

13/13 tests pass with zero ResourceWarnings. Also added
test_catalog_fixture_closes_connections to TestSqlCatalogClose as a
regression test to prevent future regressions.

Are there any user-facing changes?

No — all changes are in test files and pyproject.toml. No public API changes.

williamacostalora and others added 7 commits July 13, 2026 00:35
Fixes apache#2530 - Python 3.13's stricter ResourceWarning detection flagged
unclosed sqlite3 connections left open by SQLAlchemy connection pools
in test fixtures. The connections were being suppressed by warning
filters in pyproject.toml rather than fixed at the source.

Changes:
- Add catalog.close() / engine.dispose() teardown to 7 test fixtures
  in tests/catalog/test_sql.py (catalog_memory, catalog_sqlite,
  alchemy_engine, and 4 inline catalog creation tests)
- Add catalog.close() to 2 fixtures in tests/conftest.py
- Remove sqlite ResourceWarning filter from pyproject.toml

All 478 SQL catalog tests pass with -W error::ResourceWarning.
Ray-related warning filters left in place pending CI verification
with ray installed.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…#2530)

Adds test_catalog_fixture_closes_connections to TestSqlCatalogClose to
verify that SqlCatalog properly disposes all SQLAlchemy connections
during teardown. Prevents future regressions where catalog.close() is
accidentally removed from fixture teardown.
Documents why catalog.close() is called in fixture teardown so future
contributors understand the connection lifecycle requirement and don't
accidentally remove the fix. References issue apache#2530.
…in pyproject.toml

Add explanatory comment distinguishing between ray subprocess warnings (pending CI test)
and the resolved sqlite connection pool warnings (fixed via proper close() calls).
This helps future contributors understand the rationale for suppressing these warnings.

Fixes issue apache#2530.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…dance

Improve the SqlCatalog.close() docstring to:
- Emphasize that close() must be called in test fixture teardowns
- Explain Python 3.13+ ResourceWarning prevention
- Document the SQLAlchemy connection pool lifecycle
- Clarify importance for both test and production scenarios (blobfuse)
- Add reference to issue apache#2530

This helps future contributors understand why proper connection cleanup is essential.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add inline comments to catalog and catalog_with_warehouse fixtures explaining
the hasattr(cat, 'close') pattern. This clarifies that:
- Not all catalog implementations provide close() (REST, Glue catalogs don't)
- SQLCatalog does provide close() for proper connection cleanup
- The pattern prevents AttributeError while supporting resource cleanup
- This is essential for Python 3.13+ ResourceWarning prevention (issue apache#2530)

This helps future contributors understand why the pattern is necessary
and when they should update it if new catalog types are added.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@williamacostalora
williamacostalora marked this pull request as draft July 20, 2026 03:38
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.

Fix warnings when running with Python ≥3.13

1 participant