Skip to content

hotfix: resolve pytest db deadlock (extracted from Saurabhsing21 PR #707#712

Merged
jmadden173 merged 1 commit intojlab-sensing:mainfrom
CODEAbhinav-art:hotfix-db-deadlock
Mar 21, 2026
Merged

hotfix: resolve pytest db deadlock (extracted from Saurabhsing21 PR #707#712
jmadden173 merged 1 commit intojlab-sensing:mainfrom
CODEAbhinav-art:hotfix-db-deadlock

Conversation

@CODEAbhinav-art
Copy link
Copy Markdown
Contributor

Tracking PR

  • Name: Abhinav Mishra
  • Affiliation/Title: GSV, Contributor

Purpose of the PR

Unblocks the global backend CI pipeline by resolving an "idle in transaction" database deadlock during pytest teardown.

Summary

The pytest --cov job is currently hanging indefinitely across all open PRs after successfully completing test_cell_search_by_name. This is caused by tests not properly cleaning up SQLAlchemy sessions, leaving Postgres locked.

@Saurabhsing21 already successfully diagnosed and wrote the fix for this in backend/tests/conftest.py as part of his larger CSV streaming PR (#707). Because the maintainers are currently bandwidth-limited with finals week, I have extracted only Saurabh's conftest.py test harness improvements into this standalone hotfix.

Merging this will turn the backend checks green for all other contributors, allowing Saurabh's #707 to pass CI as well. All credit for this code goes to Saurabh.

Development Environment

  • OS: Linux (Ubuntu)
  • Python/Docker version: Python 3.11

Task List

  • Updated the CHANGELOG.md
  • Static code analysis passes
  • All environments can be built
  • All tests pass
  • Clear documentation for new code (N/A)
  • Linting passes

Relevant Issues

Closes #708

@jmadden173
Copy link
Copy Markdown
Contributor

I tested this locally and it was functional. Only error I got was an existing broken test case.

init_database = <FlaskClient <Flask 'api'>>

    def test_get_teros_obj_fraction_scales_to_percent(init_database):
        """
        GIVEN adjusted VWC stored as a fraction
        WHEN TEROS data is retrieved
        THEN VWC is returned as a percentage
        """
        ts = 1705176162
        formated_ts = datetime.fromtimestamp(ts)
        cell = Cell("cell_9", "", 1, 1, False, None)
        cell.save()
        TEROSData.add_teros_data("cell_9", formated_ts, 0.42, 2, 3, 4, 5)
    
        teros_data_obj = TEROSData.get_teros_data_obj(
            cell.id, "none", formated_ts, formated_ts, False
        )
    
        assert 42 in teros_data_obj["vwc"]
>       assert teros_data_obj["vwc_unit"] == "%"
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
E       KeyError: 'vwc_unit'

tests/test_teros_data.py:199: KeyError

@jmadden173 jmadden173 merged commit 4e0acbb into jlab-sensing:main Mar 21, 2026
1 of 2 checks passed
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.

CRITICAL: pytest hanging indefinitely (3+ hours) in CI workflow, blocking all PRs

2 participants