]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Fix missing f-string prefix in two DataError messages
authorwinklemad <winklemad@outlook.com>
Fri, 17 Jul 2026 01:09:00 +0000 (06:39 +0530)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 18 Jul 2026 18:34:48 +0000 (20:34 +0200)
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 #1372

docs/news.rst
psycopg/psycopg/types/datetime.py
psycopg/psycopg/types/json.py

index deffeb11cfc0f0a844f7a3339cd252a07a43751b..2837b6966d0937eaf612e3e65cae011daf026513 100644 (file)
@@ -19,6 +19,9 @@ Psycopg 3.3.5 (unreleased)
   no `!NoneType` dumper registered in python implementation (:ticket:`#1325`).
 - Fix `!wait_selector` wait function to not raise `!KeyError`
   (:ticket:`#1327`).
+- Fix `!DataError` messages leaking the literal ``{...}`` placeholder instead
+  of the offending value when loading a pre-year-1 :sql:`timestamp` or a
+  malformed binary :sql:`jsonb` value (:ticket:`#1372`).
 
 
 Current release
index 8bd4e0f24e6025eda8de08c9e7f5528af5b4bf5a..3226935a99d1a899e83235aed559134575f5248f 100644 (file)
@@ -689,7 +689,7 @@ def _get_timestamp_load_error(
             return len(s.split()[-1]) > 4  # year is last token
 
     if s == "-infinity" or s.endswith("BC"):
-        return DataError("timestamp too small (before year 1): {s!r}")
+        return DataError(f"timestamp too small (before year 1): {s!r}")
     elif s == "infinity" or is_overflow(s):
         return DataError(f"timestamp too large (after year 10K): {s!r}")
     else:
index 6ebab6cbeece331a1f2247cb0ad153114f19feb2..1d4a126481dd93343f7ddca08199183fd59a95fd 100644 (file)
@@ -277,7 +277,7 @@ class JsonbBinaryLoader(_JsonLoader):
 
     def load(self, data: Buffer) -> Any:
         if data and data[0] != 1:
-            raise DataError("unknown jsonb binary format: {data[0]}")
+            raise DataError(f"unknown jsonb binary format: {data[0]}")
         if not isinstance((data := data[1:]), bytes):
             data = bytes(data)
         return self.loads(data)