Skip to content

fix(ci): the test run stops warning about unclosed test databases, pydantic's deprecated Extra and starlette's BlockingPortal alias #1497

Closed

Description

@dan-petty

Filed at the owner's request from the 2026-10-09 review of GitHub Actions warnings and notices.

Problem

Checked at release/v0.2.32 (27cf6bd). The Tests & Coverage job of CI run https://github.com/dan-petty/devops-cli/actions/runs/37939949186/job/113851481357 ran on release/v0.2.31 at a6ac3f0, the same tree, and ends with 10268 passed, 24 skipped, 8 xfailed, 42 warnings. 33 of the 42 have a fix on our side.

20 × ResourceWarning: unclosed database in <sqlite3.Connection ...>: tests leave sqlite connections open

  • The summary pins each warning on whichever test was running when the garbage collector finalized the connection: 8 on test_ai_spend_ledger.py::test_devops_ai_cost_cli_by_stage, 5 on test_ai_spend_pricing.py::test_pricing_registry_offline_defaults, and the rest across five more tests. It also names sites such as genai_prices/types.py:913 and typing.py:433. None of these opened the connections.
  • A tracemalloc run (PYTHONTRACEMALLOC=10, -n 0, -W always::ResourceWarning) traced the leaks to with sqlite3.connect(path) as conn: blocks in tests. The sqlite3 connection's context manager commits or rolls back, but it does not close the connection [measured]. The 13 sites:
    • tests/test_ai_spend_ledger.py:19, :177, :208, :509, :514, :547, :575
    • tests/test_ai_served_by.py:102, :111
    • tests/test_ai_spend_dispatch.py:218, :279
    • tests/test_review_profile.py:614
    • tests/test_telemetry_instruments.py:415
  • src/ already closes its connections. The ledger uses contextlib.closing(...) (src/devops_cli/ai/spend/ledger.py:252, :289, :377, :552).
  • This command fails 6 tests in about 7 s [measured]: uv run pytest -p no:cacheprovider -q -n 0 --no-cov -W error::ResourceWarning -W error::pytest.PytestUnraisableExceptionWarning tests/test_ai_spend_ledger.py tests/test_ai_spend_dispatch.py tests/test_review_profile.py tests/test_telemetry_instruments.py

9 × PydanticDeprecatedSince20: pydantic.config.Extra is deprecated (from inspect.py:506): library ingest reads deprecated attributes

  • The warnings come 3 each from tests/test_library_ingest.py::test_introspect_installed_package, ::test_cli_ai_ingest_library and ::test_cli_ai_ingest_library_json_format. All three introspect pydantic itself.
  • _extract_methods_and_props (src/devops_cli/ai/library/introspector.py:108) calls inspect.getmembers(cls) on every public class. On pydantic 2.13.5 that reads Extra.allow, .ignore and .forbid, and the class's metaclass warns on each read (pydantic/deprecated/config.py:54-59). Stack: introspector.py:260 → :193 → :164 → :136 → :108 [measured]. devops-cli itself never uses Extra.
  • uv run pytest -p no:cacheprovider -q -n 0 --no-cov -W error::DeprecationWarning tests/test_library_ingest.py fails those 3 tests [measured].
  • inspect.getmembers_static avoids the reads, but it is not a drop-in replacement. It changes the extracted catalogue for 49 of pydantic's 264 classes; for example, it adds fromkeys to ConfigDict and model_fields to BaseModel [measured].

4 × starlette/testclient.py:53: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated: the lock holds an old starlette

  • The warning appears once per xdist worker, at collection.
  • uv.lock has starlette 1.6.0 with anyio 4.15.1. Tests import starlette through fastapi.testclient (tests/test_server.py:9, tests/test_server_stream.py:7, tests/test_server_service.py:20, tests/test_ai_spend_prometheus.py:8).
  • starlette 1.7.0 (2026-09-23), the newest release, uses anyio.from_thread.BlockingPortal (starlette/testclient.py:53 at tag 1.7.0). It requires AnyIO 4, which the lock already has.
  • Nothing holds starlette below 1.7.0: fastapi 0.142.2 needs >=0.46.0, mcp 2.3.0 >=0.48.0 and sse-starlette >=0.49.1.
  • The lock does not move on its own, because .github/renovate.json turns the pep621 manager off.

The other 9 warnings are tracked elsewhere:

Proposed remedy

  • Close every test connection with with contextlib.closing(sqlite3.connect(path)) as conn:, as ledger.py does, and add , conn where the block writes. Where a helper opens the connection (_ledger_rows, _columns, _finish_reasons), fix it in the helper.
  • In PackageIntrospector.introspect_package, read the members inside warnings.catch_warnings() with warnings.simplefilter("ignore", DeprecationWarning), plus a one-line comment. Reading a package's API to catalogue it does not use that API, and the deprecations belong to the package being read. The catalogue does not change.
  • Run uv lock --upgrade-package starlette (1.6.0 → 1.7.0).

Acceptance criteria

  • The ResourceWarning command above passes. The same flags on tests/test_ai_served_by.py report no unclosed database; its unclosed tiktoken socket belongs to fix(ai): the context-budget tokenizer downloads its encoding on first use and silently falls back to a heuristic #1421.
  • uv run pytest -p no:cacheprovider -q -n 0 --no-cov -W error::DeprecationWarning tests/test_library_ingest.py passes.
  • Apart from its timestamp, the catalogue that devops ai ingest library pydantic --max-depth 1 writes is the same as before.
  • uv.lock has starlette 1.7.0 or later, and the FastAPI TestClient server tests pass.
  • The CI pytest summary lists no unclosed database, pydantic.config.Extra or anyio.abc.BlockingPortal warning.
  • uv run devops ci passes.

Related: #1421 (tiktoken download in tests), #1329 (owns test_library_ingest.py for its edge-fake migration), #1331.

Activity

  1. added
    type/bug
    scope/ci
    on Oct 9, 2026
  2. dan-petty-bot commented on Oct 9, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P3-Low. All 10268 tests pass; these are warnings that will become errors only after future dependency upgrades, so they are hygiene rather than a blocker.
    • Value: Medium. Clean CI output reduces noise for real failures and prevents breakage when the deprecated APIs are removed in upcoming releases.
    • Effort: Medium. Thirteen test sites need explicit close calls, the introspector needs a safe member-reading path, and the starlette pin must be bumped and re-locked.
  3. added this to the v0.2.38 milestone on Oct 20, 2026
  4. dan-petty commented on Oct 20, 2026

    @dan-petty
    OwnerAuthor

    Three more warnings in the CI test summary have no owner. Folding them in here so the test run can end warning-free.

    Seen in job 118675899791 of run 39436644820 (11080 passed, 40 warnings):

    1. UserWarning: Api key is used with an insecure connection from qdrant-client, through tests/conftest.py, in tests/test_ai_subcommands_rag.py::test_try_retrieve_rag_context_success.
    2. google-genai's _UnionGenericAlias DeprecationWarning in tests/test_pydantic_ai_profiles_and_providers.py::TestPydanticAIProviders::test_native_provider_classes_and_subclasses. This item left it to upstream (DeprecationWarning: '_UnionGenericAlias' is deprecated and slated for removal in Python 3.17 googleapis/python-genai#1640). Upstream still has it open, so it needs a recorded reason or a fix here.
    3. LogfireNotConfiguredWarning from src/devops_cli/telemetry/logfire.py, in tests/test_telemetry_logfire.py::test_logfire_bridge_configuration_without_token_fallback.

    #1498 still owns the PydanticJsonSchemaWarning lines.

  5. dan-petty commented on Oct 21, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1769, merged into release/v0.2.38 as 2766e0f.

    Closes #1497

    10 file(s) changed.

    How it was verified

    Check runs at 1d0e577:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Rule Pack Tests: pass
    • Fail-to-Pass Self-Check: pass
    • Changed-Test Independence: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Fail-to-Pass Check: pass
    • Static Analysis: pass
    • Analyze (actions): pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1497-test-run-warnings.md:

    No Acceptance Criteria section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope/citype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions