Skip to content

fix: run synchronous test jobs after the outermost transaction commits (CKAN 2.12) - #6

Open
paulmueller-agent wants to merge 1 commit into
DCOR-dev:masterfrom
paulmueller-agent:sync-jobs-after-commit
Open

paulmueller-agent wants to merge 1 commit into
DCOR-dev:masterfrom
paulmueller-agent:sync-jobs-after-commit

Conversation

@paulmueller-agent

Copy link
Copy Markdown

CKAN 2.12 runs package_update in a nested transaction (session.begin_nested()) and commits it after the IPackageController hooks ran. With ckan.plugins.toolkit.enqueue_job mocked by synchronous_enqueue_job, the background jobs ran inline inside after_dataset_update. Their commits closed the nested transaction, so most tests that create datasets failed with sqlalchemy.exc.ResourceClosedError: This transaction is closed on CKAN 2.12.

synchronous_enqueue_job now:

  • runs the job immediately if there is no nested transaction (this is always the case on CKAN 2.11, so 2.11 behaviour is unchanged);
  • otherwise queues it and runs it after the outermost transaction was committed (via the SQLAlchemy session events after_commit / after_transaction_end), and drops it if that transaction is rolled back. This is what happens in production, where an RQ worker runs the job with its own session.

Testing:

  • CKAN 2.11 CI passes on this branch.
  • In trial runs on CKAN 2.12 (fork branches, using this branch and ckanext-dcor_schemas with its 2.12 fixes), the test suites of dcor_shared, ckanext-dc_log_view, ckanext-dc_serve, ckanext-dc_view, ckanext-dcor_depot and ckanext-dcor_schemas pass.
  • The session event semantics (commit, root rollback, savepoint rollback) were checked with SQLAlchemy 2.0 and SQLite.

This only affects test helpers, not production code.

🤖 Generated with Claude Code

CKAN 2.12 runs package_update in a nested transaction. Jobs that commit
the session closed it (ResourceClosedError) when executed inline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.70%. Comparing base (1732f0f) to head (1e71383).

Files with missing lines Patch % Lines
dcor_shared/testing.py 33.33% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master       #6      +/-   ##
==========================================
- Coverage   96.99%   94.70%   -2.29%     
==========================================
  Files          12       12              
  Lines         566      586      +20     
==========================================
+ Hits          549      555       +6     
- Misses         17       31      +14     
Flag Coverage Δ
develop 94.70% <33.33%> (-2.29%) ⬇️
pypi 94.70% <33.33%> (-2.29%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant