Skip to content

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

Closed

Description

@winklemad

Two DataError messages in the pure-Python implementation are plain string literals that contain {...} placeholders but are missing the f prefix, so the literal placeholder text is shown to the user instead of the offending value.

1. psycopg/types/datetime.py:692 — _get_timestamp_load_error():

return DataError("timestamp too small (before year 1): {s!r}")

The two sibling branches immediately below it are correctly f-strings (f"timestamp too large (after year 10K): {s!r}", f"can't parse timestamp {s!r}: ..."), which is what makes the missing prefix stand out.

2. psycopg/types/json.py:280 — JsonbBinaryLoader.load():

raise DataError("unknown jsonb binary format: {data[0]}")

Reproduction (pure-Python, no server needed)

from psycopg.types.datetime import _get_timestamp_load_error
from psycopg.types.json import JsonbBinaryLoader
from psycopg import _oids

print(_get_timestamp_load_error(None, b"0001-01-01 00:00:00 BC"))
# -> timestamp too small (before year 1): {s!r}

try:
    JsonbBinaryLoader(_oids.JSONB_OID, None).load(b"\x02{}")
except Exception as e:
    print(e)
# -> unknown jsonb binary format: {data[0]}

Expected

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). I'll open a PR adding the missing f prefix to both.

Activity

  1. added a commit that references this issue on Jul 18, 2026
    0f14cfe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions