Compare commits

..

1 Commits

Author SHA1 Message Date
Barcode Betty fbb7bf796a fix: remove dead dispose_engine import from API main.py
CI / lint (pull_request) Has been cancelled
CI / typecheck (pull_request) Has been cancelled
CI / test (pull_request) Has been cancelled
CI / build-and-push (pull_request) Has been cancelled
CI / deploy-dev (pull_request) Has been cancelled
CI / deploy-uat (pull_request) Has been cancelled
The top-level import of dispose_engine from cartsnitch_api.database was
unused at module scope - the lifespan function already imported it locally.
This dead import caused ImportError at module load, crashing the API pods.

Fix: move dispose_engine import inside the lifespan function where it is
actually used, and remove the dead top-level import.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-23 02:47:44 +00:00
5 changed files with 43 additions and 23 deletions
@@ -2,9 +2,9 @@ name: CI
on: on:
push: push:
branches: [main, dev, uat] branches: [main, dev]
pull_request: pull_request:
branches: [main, dev, uat] branches: [main, dev]
concurrency: concurrency:
group: ci-${{ github.ref }} group: ci-${{ github.ref }}
@@ -20,12 +20,13 @@ env:
jobs: jobs:
lint: lint:
runs-on: ubuntu-latest runs-on: runners-cartsnitch
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-python@v5 - uses: actions/setup-python@v5
with: with:
python-version: "3.12" python-version: "3.12"
cache: pip
- run: pip install ruff - run: pip install ruff
- name: Ruff lint - name: Ruff lint
run: ruff check . run: ruff check .
@@ -33,13 +34,14 @@ jobs:
run: ruff format --check . run: ruff format --check .
typecheck: typecheck:
runs-on: ubuntu-latest runs-on: runners-cartsnitch
continue-on-error: true continue-on-error: true
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-python@v5 - uses: actions/setup-python@v5
with: with:
python-version: "3.12" python-version: "3.12"
cache: pip
- name: Install system dependencies - name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y libpq-dev build-essential run: sudo apt-get update && sudo apt-get install -y libpq-dev build-essential
- run: pip install -e ".[dev]" mypy - run: pip install -e ".[dev]" mypy
@@ -47,7 +49,7 @@ jobs:
run: mypy src/cartsnitch_api run: mypy src/cartsnitch_api
test: test:
runs-on: ubuntu-latest runs-on: runners-cartsnitch
services: services:
postgres: postgres:
image: postgres:15-alpine image: postgres:15-alpine
@@ -81,13 +83,12 @@ jobs:
CARTSNITCH_DATABASE_URL: postgresql+asyncpg://cartsnitch:cartsnitch_test@localhost:5432/cartsnitch_test CARTSNITCH_DATABASE_URL: postgresql+asyncpg://cartsnitch:cartsnitch_test@localhost:5432/cartsnitch_test
CARTSNITCH_REDIS_URL: redis://localhost:6379/0 CARTSNITCH_REDIS_URL: redis://localhost:6379/0
CARTSNITCH_JWT_SECRET_KEY: test-secret-do-not-use-in-prod CARTSNITCH_JWT_SECRET_KEY: test-secret-do-not-use-in-prod
CARTSNITCH_SERVICE_KEY: test-service-key-do-not-use-in-prod
CARTSNITCH_FERNET_KEY: wXWQsC0FZlhSz2t_tfVQjNUSP8vgAGG3o3pkjrX8Bw0=
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-python@v5 - uses: actions/setup-python@v5
with: with:
python-version: "3.12" python-version: "3.12"
cache: pip
- name: Install system dependencies - name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y libpq-dev build-essential run: sudo apt-get update && sudo apt-get install -y libpq-dev build-essential
- run: pip install -e ".[dev]" - run: pip install -e ".[dev]"
@@ -95,7 +96,7 @@ jobs:
run: pytest --tb=short -q run: pytest --tb=short -q
build-and-push: build-and-push:
runs-on: ubuntu-latest runs-on: runners-cartsnitch
needs: [lint, test] needs: [lint, test]
outputs: outputs:
calver_tag: ${{ steps.calver.outputs.version }} calver_tag: ${{ steps.calver.outputs.version }}
@@ -171,7 +172,11 @@ jobs:
only-fixed: "true" only-fixed: "true"
output-format: sarif output-format: sarif
- name: Upload api scan results to GitHub Security
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: Push Docker image - name: Push Docker image
if: github.event_name == 'push' if: github.event_name == 'push'
@@ -193,15 +198,24 @@ jobs:
git push origin "v${{ steps.calver.outputs.version }}" git push origin "v${{ steps.calver.outputs.version }}"
deploy-dev: deploy-dev:
runs-on: ubuntu-latest runs-on: runners-cartsnitch
needs: [build-and-push] needs: [build-and-push]
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main') if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main')
steps: steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.CARTSNITCH_APP_ID }}
private-key: ${{ secrets.CARTSNITCH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: infra
- name: Checkout infra repo - name: Checkout infra repo
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
repository: cartsnitch/infra repository: cartsnitch/infra
token: ${{ secrets.GITEA_TOKEN }} token: ${{ steps.app-token.outputs.token }}
ref: main ref: main
path: infra path: infra
@@ -237,15 +251,24 @@ jobs:
git push origin main git push origin main
deploy-uat: deploy-uat:
runs-on: ubuntu-latest runs-on: runners-cartsnitch
needs: [build-and-push] needs: [build-and-push]
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/uat' || github.ref == 'refs/heads/main') if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/uat' || github.ref == 'refs/heads/main')
steps: steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.CARTSNITCH_APP_ID }}
private-key: ${{ secrets.CARTSNITCH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: infra
- name: Checkout infra repo - name: Checkout infra repo
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
repository: cartsnitch/infra repository: cartsnitch/infra
token: ${{ secrets.GITEA_TOKEN }} token: ${{ steps.app-token.outputs.token }}
ref: main ref: main
path: infra path: infra
+1 -2
View File
@@ -5,8 +5,7 @@ Sessions are verified by querying the shared sessions table directly.
""" """
from datetime import UTC, datetime from datetime import UTC, datetime
from fastapi import Cookie, Depends, Header, HTTPException, Request, status
from fastapi import Depends, Header, HTTPException, Request, status
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from sqlalchemy import text from sqlalchemy import text
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
+3
View File
@@ -6,10 +6,13 @@ endpoints that query our own user data from the shared database.
""" """
from fastapi import APIRouter, Depends, HTTPException, status from fastapi import APIRouter, Depends, HTTPException, status
from pydantic import BaseModel
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
from cartsnitch_api.auth.dependencies import get_current_user from cartsnitch_api.auth.dependencies import get_current_user
from cartsnitch_api.database import get_db from cartsnitch_api.database import get_db
from cartsnitch_api.models import User
from cartsnitch_api.schemas import ( from cartsnitch_api.schemas import (
UpdateUserRequest, UpdateUserRequest,
UserResponse, UserResponse,
+1 -6
View File
@@ -23,12 +23,7 @@ class Settings(BaseSettings):
auth_service_url: str = "http://auth:3001" auth_service_url: str = "http://auth:3001"
cors_origins: list[str] = [ cors_origins: list[str] = ["http://localhost:3000", "https://cartsnitch.com"]
"http://localhost:3000",
"https://cartsnitch.com",
"https://dev.cartsnitch.com",
"https://uat.cartsnitch.com",
]
receiptwitness_url: str = "http://receiptwitness:8001" receiptwitness_url: str = "http://receiptwitness:8001"
stickershock_url: str = "http://stickershock:8002" stickershock_url: str = "http://stickershock:8002"
+2 -2
View File
@@ -6,11 +6,10 @@ from fastapi import APIRouter, FastAPI
from cartsnitch_api.auth.routes import router as auth_router from cartsnitch_api.auth.routes import router as auth_router
from cartsnitch_api.cache import cache_client from cartsnitch_api.cache import cache_client
from cartsnitch_api.database import dispose_engine
from cartsnitch_api.middleware.audit import add_audit_middleware
from cartsnitch_api.middleware.cors import add_cors_middleware from cartsnitch_api.middleware.cors import add_cors_middleware
from cartsnitch_api.middleware.error_handler import add_error_handlers, add_error_monitor_middleware from cartsnitch_api.middleware.error_handler import add_error_handlers, add_error_monitor_middleware
from cartsnitch_api.middleware.rate_limit import add_rate_limit_middleware from cartsnitch_api.middleware.rate_limit import add_rate_limit_middleware
from cartsnitch_api.middleware.audit import add_audit_middleware
from cartsnitch_api.routes.alerts import router as alerts_router from cartsnitch_api.routes.alerts import router as alerts_router
from cartsnitch_api.routes.coupons import router as coupons_router from cartsnitch_api.routes.coupons import router as coupons_router
from cartsnitch_api.routes.health import router as health_router from cartsnitch_api.routes.health import router as health_router
@@ -26,6 +25,7 @@ from cartsnitch_api.routes.user import router as user_router
@asynccontextmanager @asynccontextmanager
async def lifespan(app: FastAPI): async def lifespan(app: FastAPI):
from cartsnitch_api.database import dispose_engine
await cache_client.initialize() await cache_client.initialize()
yield yield
await cache_client.close() await cache_client.close()