Skip to content

Commit 619388a

Browse files
authored
Merge pull request #26 from MauricioReisdoefer/main
2 parents b801e98 + ed5d046 commit 619388a

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ on:
44
branches:
55
- main
66

7-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
87
permissions:
98
contents: read
109
pages: write
1110
id-token: write
1211

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

4340
deploy:
41+
if: github.event.repository.fork == false
4442
environment:
4543
name: github-pages
4644
url: ${{ steps.deployment.outputs.page_url }}

jsweb/middleware.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,24 @@ async def __call__(self, scope, receive, send):
175175

176176
from .database import db_session
177177
try:
178-
await self.app(scope, receive, send)
179-
db_session.commit()
178+
status_code = None
179+
180+
async def send_wrapper(message):
181+
nonlocal status_code
182+
if message["type"] == "http.response.start":
183+
status_code = message["status"]
184+
await send(message )
185+
186+
await self.app(scope, receive, send_wrapper)
187+
188+
# Commit only if the response status code is a success (2xx)
189+
# If status_code is None, it means no response was sent, which is an error state
190+
# or a successful response that didn't send headers yet (unlikely in a standard flow).
191+
# It's safer to rollback if status_code is not set or is not 2xx.
192+
if status_code is not None and 200 <= status_code < 300:
193+
db_session.commit()
194+
else:
195+
db_session.rollback()
180196
except Exception:
181197
db_session.rollback()
182198
raise

0 commit comments

Comments
 (0)