Skip to content

in fetch.get_interval, make sure db is closed#286

Merged
javierggt merged 1 commit intomasterfrom
unclosed-db
Dec 10, 2025
Merged

in fetch.get_interval, make sure db is closed#286
javierggt merged 1 commit intomasterfrom
unclosed-db

Conversation

@javierggt
Copy link
Contributor

@javierggt javierggt commented Dec 5, 2025

Description

This PR fixes a warning that appears in python 3.13 (ska3-hope).

This is the warning:

cheta/cheta/tests/test_comps.py::test_quat_comp_bad_times
  /Users/javierg/miniforge3/envs/ska3-flight-2026.0rc4/lib/python3.13/site-packages/_pytest/unraisableexception.py:67: PytestUnraisableExceptionWarning: Exception ignored in: <sqlite3.Connection object at 0x12da75c60>
  
  Traceback (most recent call last):
    File "<frozen importlib._bootstrap_external>", line 781, in _compile_bytecode
  ResourceWarning: unclosed database in <sqlite3.Connection object at 0x12da75c60>

The cause for the warning is a Ska.DBI instance that seems to be kept alive inside a cached result. Somehow a reference to the db is attached to the cached result even if it is not necessary, and at exit the connection is still open.

The fix in this PR is to explicitly close it by using the context manager.

Interface impacts

Testing

Unit tests

  • Linux
(ska3-flight-2026.0rc4) jgonzale cheta $ git rev-parse HEAD
fccd7ff016f6d034c601d3915a01545a248ae84b
(ska3-flight) jgonzale cheta $ pytest cheta
==================================================================== test session starts =====================================================================
platform linux -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
rootdir: /proj/sot/ska/jgonzalez/git
configfile: pytest.ini
plugins: anyio-4.7.0, timeout-2.3.1
collected 187 items                                                                                                                                          

cheta/tests/test_comps.py .............ss.......................................................                                                       [ 37%]
cheta/tests/test_data_source.py ...........                                                                                                            [ 43%]
cheta/tests/test_fetch.py .................................                                                                                            [ 60%]
cheta/tests/test_intervals.py .........................                                                                                                [ 74%]
cheta/tests/test_orbit.py .                                                                                                                            [ 74%]
cheta/tests/test_remote_access.py ......                                                                                                               [ 78%]
cheta/tests/test_sync.py ........                                                                                                                      [ 82%]
cheta/tests/test_units.py ...........                                                                                                                  [ 88%]
cheta/tests/test_units_reversed.py ...........                                                                                                         [ 94%]
cheta/tests/test_utils.py ...........                                                                                                                  [100%]

====================================================================== warnings summary ======================================================================
cheta/cheta/tests/test_comps.py::test_cmd_states
  /export/jgonzale/miniconda3/envs/ska3-flight/lib/python3.12/site-packages/setuptools_scm/git.py:312: UserWarning: git archive did not support describe output
    warnings.warn("git archive did not support describe output")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================== 185 passed, 2 skipped, 1 warning in 167.95s (0:02:47) ====================================================
(ska3-flight) jgonzale cheta $ conda activate ska3-flight-2026.0rc4
(ska3-flight-2026.0rc4) jgonzale cheta $ pytest cheta
==================================================================== test session starts =====================================================================
platform linux -- Python 3.13.10, pytest-9.0.1, pluggy-1.6.0
rootdir: /proj/sot/ska/jgonzalez/git
configfile: pytest.ini
plugins: timeout-2.4.0, anyio-4.12.0
collected 187 items                                                                                                                                          

cheta/tests/test_comps.py .............ss.......................................................                                                       [ 37%]
cheta/tests/test_data_source.py ...........                                                                                                            [ 43%]
cheta/tests/test_fetch.py .................................                                                                                            [ 60%]
cheta/tests/test_intervals.py .........................                                                                                                [ 74%]
cheta/tests/test_orbit.py .                                                                                                                            [ 74%]
cheta/tests/test_remote_access.py ......                                                                                                               [ 78%]
cheta/tests/test_sync.py ........                                                                                                                      [ 82%]
cheta/tests/test_units.py ...........                                                                                                                  [ 88%]
cheta/tests/test_units_reversed.py ...........                                                                                                         [ 94%]
cheta/tests/test_utils.py ...........                                                                                                                  [100%]

====================================================================== warnings summary ======================================================================
cheta/cheta/tests/test_comps.py::test_cmd_states
  /export/jgonzale/miniconda3/envs/ska3-flight-2026.0rc4/lib/python3.13/site-packages/setuptools_scm/git.py:427: UserWarning: git archive did not support describe output
    warnings.warn("git archive did not support describe output")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================== 185 passed, 2 skipped, 1 warning in 178.66s (0:02:58) ====================================================

Independent check of unit tests by [REVIEWER NAME]

  • [PLATFORM]:

Functional tests

No functional testing.

@javierggt javierggt merged commit 6a5367a into master Dec 10, 2025
2 checks passed
@javierggt javierggt deleted the unclosed-db branch December 10, 2025 13:26
This was referenced Jan 20, 2026
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.

2 participants