Skip to content

chore: remove unused flask dependency and make SQL echo configurable via env var#453

Open
Arijit429 wants to merge 10 commits intofireform-core:mainfrom
Arijit429:fix/cleanup-requirements-and-db-echo
Open

chore: remove unused flask dependency and make SQL echo configurable via env var#453
Arijit429 wants to merge 10 commits intofireform-core:mainfrom
Arijit429:fix/cleanup-requirements-and-db-echo

Conversation

@Arijit429
Copy link
Copy Markdown

Closes #370
Closes #372

Summary

Two small cleanups bundled together — both touch production readiness
and reduce noise in production deployments.

Problem 1 — Unused flask dependency (#370)

flask is listed in requirements.txt but is never imported anywhere
in the project. The project uses FastAPI. This bloats Docker images,
increases install time, and creates confusion for new contributors about
which framework the project actually uses.

Problem 2 — Hardcoded SQL echo (#372)

api/db/database.py had echo=True hardcoded, which prints every single
SQL query
to stdout. In development this is noisy but tolerable. In
production, this:

  • Floods logs with SQL statements
  • Makes real errors harder to find
  • Can leak query patterns in log aggregators

Changes

requirements.txt

  • Removed unused flask dependency

api/db/database.py

  • Replaced hardcoded echo=True with SQL_ECHO environment variable
  • Defaults to false — quiet logs in production
  • Opt-in via SQL_ECHO=true uvicorn api.main:app for debugging

Testing

  • Default: server starts with no SQL query spam
  • SQL_ECHO=true: SQL queries appear in logs as before
  • All endpoints work correctly in both modes
  • Existing tests pass

Changes Summary

File Change Why
requirements.txt Remove flask Unused dependency bloats image
api/db/database.py SQL_ECHO env var Quiet logs in production, opt-in for debugging

- Add HTTPException handler for consistent error shape across all routes
- Add RequestValidationError handler with human-readable error messages
- Add catch-all Exception handler to prevent stack trace leakage
- Fix duplicate get_template() call in forms.py (was querying DB twice)
- Wrap Controller errors in AppError for safe client-facing messages
- All errors now return uniform {success, error: {code, message}} envelope
…file

- Add GET /health liveness probe for Docker and container orchestration
- Migrate database init from module-level to FastAPI lifespan context manager
- Fix Dockerfile: start uvicorn server instead of tail -f /dev/null
- Fix Dockerfile: correct PYTHONPATH from /app/src to /app
- Add Docker HEALTHCHECK directive using /health endpoint
- Add EXPOSE 8000 for container port documentation
- Add FastAPI metadata (title, description, version) for API docs
- Enforce 20 MB max upload size (returns 413 if exceeded)
- Validate PDF magic bytes to reject non-PDF files renamed to .pdf
- Reject empty file uploads with clear 400 error
- Add matching client-side size and empty file checks for instant UX feedback
- Server-side validation is the security authority, client checks are UX only
- Add 120s timeout to prevent indefinite request hangs
- Add retry logic (3 attempts) with exponential backoff (2s, 4s, 8s)
- Retry on timeouts, connection errors, and 5xx server errors
- Do not retry on 4xx client errors (permanent failures)
- Extract _call_ollama() method for testability
- Replace print() statements with structured logging
- Add per-field logging for extraction debugging
…itization

- Add min_length=1 and max_length=50000 to input_text field
- Add whitespace-only rejection via field_validator
- Auto-strip leading/trailing whitespace from input before LLM
- Add template name validation (min 1, max 200 chars)
- Add pdf_path minimum length validation
- Fix deprecated class Config to model_config in both schema files
- Prevents empty prompts and oversized payloads reaching LLM pipeline
- Run pytest on every push to main and every pull request
- Run ruff linter for Python code quality checks
- Cache pip dependencies for faster CI runs
- Set PYTHONPATH for correct module resolution
- Two parallel jobs: test and lint
…utc)

Closes fireform-core#444

- Replace datetime.utcnow() in models.py default_factory
- Replace datetime.utcnow() in templates.py timestamp generation
- Fixes DeprecationWarning visible in pytest output on Python 3.12+
Closes fireform-core#442

- Add slowapi-based rate limiting middleware
- Limit /forms/fill to 20 requests/minute per client IP
- Return uniform 429 response matching ErrorResponse schema
- Register rate limiter in app startup
- Prevents DoS via repeated LLM extraction requests
Closes fireform-core#370
Closes fireform-core#372

- Remove unused flask dependency from requirements.txt (never imported)
- Replace hardcoded echo=True with SQL_ECHO environment variable
- SQL echo defaults to false in production, opt-in via SQL_ECHO=true
- Prevents SQL query spam from polluting stdout logs by default
@Arijit429
Copy link
Copy Markdown
Author

Context

Two small cleanups bundled — removes the unused flask dependency (#370) that was confusing new contributors about which framework the project uses, and makes SQL echo opt-in via environment variable (#372) so production logs aren't flooded with query output. Both changes are backward-compatible for dev workflows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant