Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rollback logs warning on clean sessions [DIA-40867] #52

Merged
merged 3 commits into from
Apr 12, 2022
Merged
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion fastapi_sqla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ def get_users(session: fastapi_sqla.Session = Depends()):
if response.status_code >= 400:
# If ever a route handler returns an http exception, we do not want the
# session opened by current context manager to commit anything in db.
logger.warning("http error, rolling back", status_code=response.status_code)
if session.dirty:
# optimistically only log if there's uncommited changes
logger.warning(
"http error, rolling back possibly uncommitted changes",
status_code=response.status_code,
)
# since this is no-op if session is not dirty, we can always call it
await loop.run_in_executor(None, session.rollback)

return response
Expand Down