Skip to content

fix: reject values the columns cannot store with a 422 - #2695

Merged
lbesson merged 1 commit into
masterfrom
fix/schema-storage-limits
Nov 23, 2026
Merged

lbesson merged 1 commit into
masterfrom
fix/schema-storage-limits

Conversation

@lbesson

@lbesson lbesson commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Forum topic 371560: a multi-week trek with height_diff_up 35000 could not be saved. height_diff_up is a smallint column, PostgreSQL refused the value, and the API answered a 500 ("unexpected error, please consult the server logs").

The schemas now refuse any value their column cannot store with a 422 naming the field:

  • SmallInt (±32767) for every smallint column (books, images, outings, routes, waypoints, xreports); Int is bounded to int32.
    Errors use the FastAPI format: less_than_equal / greater_than_equal with ctx.le / ctx.ge.
  • Str(n) lengths for varchar(n) columns that had none: the update message (history_metadata.comment, 200), the registration email (200), and the SSO email, username and name (200). OneOf gets the length of its longest choice.
  • SSO external_id is an Int. forum_username keeps its own check (validate_forum_username, a 400 as before).

tests/schemas/test_storage_limits.py walks every ModelSchema and checks each integer and String(n) field against its column, so a new field without a bound fails the tests. That test is how the registration email gap was found.

The DB column stays smallint: a trek over 32 km of height difference is rare enough to stay an exception. The UI side is c2corg/c2c_ui#5226.

🤖 Generated with Claude Code

An outing with a height difference of 35000 m failed with a 500
("smallint out of range"). The integer fields now have the range of
their column (SmallInt for smallint columns, Int for integer ones),
answered with pydantic's error types (less_than_equal and
greater_than_equal, with the limit in ctx) so the UI can translate them.

Also bounded: the update message (history_metadata.comment is a
varchar(200)), the registration email (varchar(200)), and the SSO sync
fields (external_id is an integer column, email/username/name are
varchar(200)).

A test checks every field of the model schemas against its column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 30 complexity · -2 duplication

Metric Results
Complexity 30
Duplication -2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@lbesson
lbesson merged commit e46bac5 into master Nov 23, 2026
7 of 11 checks passed
@lbesson
lbesson deleted the fix/schema-storage-limits branch November 23, 2026 12:36
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.

1 participant