Skip to content

Backend: Database session is not rolled back when user/org creation fails #136

@charu2210

Description

@charu2210

Description

When create_user() or create_organization() fails during await self.db_session.commit() in backend/app/utils/jwt_auth.py, the exception is re-raised without calling await self.db_session.rollback().

This leaves the SQLAlchemy session in a failed transaction state, which can cause later DB operations to fail with PendingRollbackError.

Steps to Reproduce

  1. Trigger a DB commit failure during signup/org creation
  2. Attempt another DB operation using the same session
  3. Observe transaction/session errors

Expected Behavior

The DB session should be rolled back after a failed commit.

Actual Behavior

The session remains in an invalid transaction state.

Suggested Fix

Add rollback handling inside the exception blocks:

except Exception:
    await self.db_session.rollback()
    raise

Environment

  • Backend
  • FastAPI
  • SQLAlchemy AsyncSession

Metadata

Metadata

Assignees

No one assigned

    Labels

    BackendfrontendReact / TypeScript frontendgssoc2026GSSoC 2026 contribution

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions