Skip to content

added sql rollbacks#243

Open
grallewellyn wants to merge 3 commits into
developfrom
sql-rollback-ogc
Open

added sql rollbacks#243
grallewellyn wants to merge 3 commits into
developfrom
sql-rollback-ogc

Conversation

@grallewellyn

@grallewellyn grallewellyn commented Jun 9, 2026

Copy link
Copy Markdown
Member

I wanted to deploy but deployments are failing to DIT and UAT with this error message

Run echo "Deploy mas.dit.maap-project.org/root/maap-api-nasa-ci/maap-project/maap-api-nasa:DIT to DIT"
Deploy mas.dit.maap-project.org/root/maap-api-nasa-ci/maap-project/maap-api-nasa:DIT to DIT
+++ dirname -- /home/ubuntu/actions-runner/_work/maap-api-nasa/maap-api-nasa/.github/workflows/deploy-on-runner.sh
++ cd -- /home/ubuntu/actions-runner/_work/maap-api-nasa/maap-api-nasa/.github/workflows
++ pwd
+ SCRIPT_DIR=/home/ubuntu/actions-runner/_work/maap-api-nasa/maap-api-nasa/.github/workflows
+ ssh -i '***' *** 'docker compose -f docker-compose-maap-api.yml down'
time="2026-06-09T23:45:48Z" level=warning msg="/home/ubuntu/docker-compose-maap-api.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion"
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Fixes: #242

@sujen1412

Copy link
Copy Markdown
Collaborator

Suggestion: Add a global teardown_request hook

The per-endpoint rollbacks in this PR are good for letting individual requests fail gracefully, but they don't fully prevent dirty sessions from leaking between requests if any unpatched endpoint hits a DB error.

A global teardown_request hook in maapapp.py would act as a systemic safety net:

@app.teardown_request
def teardown_request(exception):
    if exception:
        db.session.rollback()
    db.session.remove()

db.session.remove() tears down the SQLAlchemy session at the end of every request and returns the connection to the pool — so no dirty state can carry over to the next request regardless of which endpoint caused the failure. This is what would have prevented the PendingRollbackError we saw in production today cascading across requests.

With this in place, the per-endpoint rollbacks here are still worth keeping for request-level error handling (so the current request can return a meaningful error instead of a 500), but the teardown hook covers everything else.

@sonarqubecloud

Copy link
Copy Markdown

@grallewellyn

Copy link
Copy Markdown
Member Author

Implemented @sujen1412's suggestion and fixed the API deployment pipeline problem that was stopping us from deploying the DIT API
This is deployed on the DIT API now

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