Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ on:
branches:
- main

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
Expand Down Expand Up @@ -41,6 +38,7 @@ jobs:
path: 'site'

deploy:
if: github.event.repository.fork == false
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
Expand Down
20 changes: 18 additions & 2 deletions jsweb/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,24 @@ async def __call__(self, scope, receive, send):

from .database import db_session
try:
await self.app(scope, receive, send)
db_session.commit()
status_code = None

async def send_wrapper(message):
nonlocal status_code
if message["type"] == "http.response.start":
status_code = message["status"]
await send(message )

await self.app(scope, receive, send_wrapper)

# Commit only if the response status code is a success (2xx)
# If status_code is None, it means no response was sent, which is an error state
# or a successful response that didn't send headers yet (unlikely in a standard flow).
# It's safer to rollback if status_code is not set or is not 2xx.
if status_code is not None and 200 <= status_code < 300:
db_session.commit()
else:
db_session.rollback()
except Exception:
db_session.rollback()
raise
Expand Down
Loading