Skip to content

Update ruff to be more strict#2279

Open
nielsond wants to merge 13 commits intofastapi:masterfrom
nielsond:update-ruff-to-be-more-strict
Open

Update ruff to be more strict#2279
nielsond wants to merge 13 commits intofastapi:masterfrom
nielsond:update-ruff-to-be-more-strict

Conversation

@nielsond
Copy link
Copy Markdown

@nielsond nielsond commented May 9, 2026

This pull request migrates the development email testing setup from Mailcatcher to Mailpit, updates related documentation and configuration, and introduces several improvements and cleanups across the backend and frontend. The most notable changes are the replacement of Mailcatcher with Mailpit for local email testing, updates to environment and configuration files, and improvements to Python code for better standards compliance and clarity.

Email Testing Migration and Configuration:

  • Replaced Mailcatcher with Mailpit in Docker Compose (compose.override.yml), including service name, image, ports, and environment variables. All references to Mailcatcher in documentation (README.md, development.md) and frontend tests have been updated to Mailpit and its new UI port (8025). [1] [2] [3] [4] [5] [6] [7] [8] [9]

  • Updated example environment variables (.example.env, renamed from .env) to use Mailpit defaults, such as SMTP_HOST=localhost, SMTP_PORT=1025, EMAILS_FROM_EMAIL=noreply@example.com, and clarified email sender name and TLS/SSL usage.

  • Added a new utility script backend/scripts/send_test_email.py to send test emails using current environment or .env settings, aiding developers in verifying email configuration.

Backend Code Modernization and Cleanup:

  • Updated all usages of timezone-aware datetime creation to use the Python 3.11+ UTC constant instead of timezone.utc, improving clarity and future compatibility in files such as models.py, security.py, and utils.py. [1] [2] [3] [4] [5]

  • Cleaned up Alembic migration scripts by removing unnecessary imports and standardizing import order for consistency and readability. [1] [2] [3] [4] [5]

  • Improved error handling in the get_current_user dependency to chain exceptions using from err, providing better traceback and debugging information.

Tooling and Linting Updates:

  • Upgraded Ruff linter configuration in pyproject.toml to target Python 3.12, enabled additional linting rules, and adjusted formatting settings for improved code quality and consistency.

Frontend Route Generation Fix:

  • Fixed the generated route tree (frontend/src/routeTree.gen.ts) to correctly represent the index route ('/') and its type mapping, ensuring type safety and correct route resolution. [1] [2] [3]

Copilot AI review requested due to automatic review settings May 9, 2026 07:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates local email testing from Mailcatcher to Mailpit across Docker Compose, docs, and Playwright tests, and tightens backend linting by making Ruff more strict while modernizing some Python code patterns.

Changes:

  • Replace Mailcatcher with Mailpit (compose override, docs, Playwright email test utilities).
  • Update Ruff configuration and apply related cleanup/modernizations (imports, exception chaining, datetime handling).
  • Fix generated TanStack router route tree typings for the index route.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
tasklist.yaml Adds a task runner config for dev/stop/lint/test commands.
README.md Updates local email testing reference from Mailcatcher to Mailpit.
frontend/tests/utils/mailpit.ts Switches Playwright email polling utility to Mailpit API and new response shape.
frontend/tests/reset-password.spec.ts Updates reset-password E2E flow to read email HTML via Mailpit API.
frontend/src/routeTree.gen.ts Corrects generated route mappings for '/' and layout fullPath.
development.md Updates local development docs to reference Mailpit and port 8025.
compose.override.yml Replaces Mailcatcher service with Mailpit and updates env vars/ports.
backend/scripts/send_test_email.py Adds a helper script to send a test email using SMTP env settings.
backend/pyproject.toml Tightens Ruff config (target-version/rules) and formatting settings.
backend/app/utils.py Updates UTC datetime creation used for password reset tokens.
backend/app/models.py Updates UTC datetime helper used in models.
backend/app/core/security.py Updates JWT expiry datetime creation.
backend/app/core/config.py Replaces typing_extensions.Self usage with typing.Self.
backend/app/api/deps.py Chains credential validation exceptions (raise ... from err).
backend/app/alembic/versions/fe56fa70289e_add_created_at_to_user_and_item.py Cleans migration imports.
backend/app/alembic/versions/d98dd8ec85a3_edit_replace_id_integers_in_all_models_.py Cleans migration imports.
backend/app/alembic/versions/9c0a54914c78_add_max_length_for_string_varchar_.py Cleans migration imports.
backend/app/alembic/versions/1a31ce608336_add_cascade_delete_relationships.py Cleans migration imports.
backend/app/alembic/env.py Removes an unused import.
.gitignore Ignores generated TS files and .env.
.example.env Updates example SMTP defaults to Mailpit-friendly local settings.
Comments suppressed due to low confidence (1)

frontend/tests/utils/mailpit.ts:32

  • The Mailpit API request response isn’t checked before calling response.json(). If Mailpit is unavailable or returns a non-2xx response, this will throw a less actionable JSON parse error. Consider asserting response.ok() (or checking status()) and throwing a clearer error that includes the status/body.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tasklist.yaml
Comment on lines +4 to +19
dev:
desc: Start the full development stack
cmds: - docker compose up -d

stop:
desc: Stop all services
cmds: - docker compose down

lint:
desc: Run ultra-fast linting and formatting
cmds: - cd backend && uv run ruff check . --fix - cd backend && uv run ruff format .

gate:
desc: Run all quality gates (Lint + Tests)
deps: [lint]
cmds: - cd backend && uv run pytest
Comment thread backend/app/utils.py
Comment on lines 1 to 5
import logging
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta
from pathlib import Path
from typing import Any
Comment thread backend/app/models.py
Comment on lines 1 to 3
import uuid
from datetime import datetime, timezone
from datetime import UTC, datetime

Comment thread backend/app/core/security.py Outdated
Comment on lines 1 to 3
from datetime import UTC, datetime, timedelta
from typing import Any

Comment on lines 1 to 5
import secrets
import warnings
from typing import Annotated, Any, Literal
from typing import Annotated, Any, Literal, Self

from pydantic import (
Comment on lines +8 to 11

import sqlalchemy as sa
import sqlmodel.sql.sqltypes
from alembic import op
from sqlalchemy.dialects import postgresql
Comment on lines +9 to +10
import sqlalchemy as sa
from alembic import op
Comment on lines +9 to +10
import sqlalchemy as sa
from alembic import op
`${process.env.MAILCATCHER_HOST}/messages/${emailData.id}.html`,
const htmlResponse = await request.get(
`${process.env.MAILPIT_HOST}/api/v1/message/${emailData.ID}/part/html`,
)
Comment on lines +110 to +113
const htmlResponse = await request.get(
`${process.env.MAILPIT_HOST}/api/v1/message/${emailData.ID}/part/html`,
)
const html = await htmlResponse.text()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants