Skip to content

Fix missing f-string prefix in two DataError messages - #1373

Merged
dvarrazzo merged 1 commit into
psycopg:masterfrom
winklemad:fix-dataerror-fstring-messages
Jul 18, 2026
Merged

dvarrazzo merged 1 commit into
psycopg:masterfrom
winklemad:fix-dataerror-fstring-messages

Conversation

@winklemad

Copy link
Copy Markdown
Contributor

Two DataError messages were built from plain string literals containing {...} placeholders but missing the f prefix, so the literal placeholder text was shown to the user instead of the offending value.

  • psycopg/types/datetime.py — _get_timestamp_load_error():
    "timestamp too small (before year 1): {s!r}"
  • psycopg/types/json.py — JsonbBinaryLoader.load():
    "unknown jsonb binary format: {data[0]}"

The two sibling branches right next to the datetime message are already f-strings (f"timestamp too large (after year 10K): {s!r}", f"can't parse timestamp {s!r}: ..."), which is what makes the omission stand out.

Before

timestamp too small (before year 1): {s!r}
unknown jsonb binary format: {data[0]}

After

timestamp too small (before year 1): '0001-01-01 00:00:00 BC'
unknown jsonb binary format: 2

A repo-wide grep confirms these are the only two occurrences of the pattern; every other {...}-in-a-plain-string case is an intentional sql.SQL(...).format(...) template.

Fixes #1372

Two error messages were built from plain string literals containing
{...} placeholders but missing the f prefix, so the literal placeholder
text was shown to the user instead of the offending value:

- types/datetime.py: "timestamp too small (before year 1): {s!r}"
- types/json.py: "unknown jsonb binary format: {data[0]}"

The sibling branches next to the datetime message are already f-strings,
which is what makes the omission stand out. Add the missing prefix to
both so the value is interpolated.

Fixes psycopg#1372
@dvarrazzo
dvarrazzo merged commit 0f14cfe into psycopg:master Jul 18, 2026
49 checks passed
@dvarrazzo

Copy link
Copy Markdown
Member

Merged, thank you!

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.

DataError messages leak the literal {...} placeholder (missing f-string prefix)

2 participants