From 3b27b2220d7617f35933be322f055c930c85ed64 Mon Sep 17 00:00:00 2001 From: Laurence Isla Date: Thu, 4 Dec 2025 21:07:50 -0500 Subject: [PATCH] fix: regression that truncates error message when offset is out of bounds - Happens when offset > the number of rows and when "Prefer: count=exact" header is sent - Regression introduced in commit 57ef998 --- CHANGELOG.md | 3 +++ src/PostgREST/Response.hs | 2 +- test/spec/Feature/Query/RangeSpec.hs | 9 ++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa9363bdb..936ed2121 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ All notable changes to this project will be documented in this file. From versio ## [14.1] - 2025-11-05 +- Fix regression where the `PGRST103` error response was truncated by @laurenceisla in #4455 + + Happened when an `offset` was greater than the rows requested and `Prefer: count=exact` was sent. + ## Fixed - Fix `db-pre-config` function failing when function names are pg reserved words by @taimoorzaeem in #4380 diff --git a/src/PostgREST/Response.hs b/src/PostgREST/Response.hs index 065c722f7..1334d7771 100644 --- a/src/PostgREST/Response.hs +++ b/src/PostgREST/Response.hs @@ -65,7 +65,7 @@ actionResponse :: DbResult -> ApiRequest -> (Text, Text) -> AppConfig -> SchemaC actionResponse (DbCrudResult WrappedReadPlan{pMedia, wrHdrsOnly=headersOnly, crudQi=identifier} RSStandard{..}) ctxApiRequest@ApiRequest{iPreferences=Preferences{..},..} _ _ _ _ _ = do let (status, contentRange) = RangeQuery.rangeStatusHeader iTopLevelRange rsQueryTotal rsTableTotal - cLHeader = if headersOnly then mempty else [contentLengthHeaderStrict rsBody] + cLHeader = if headersOnly then mempty else [contentLengthHeaderLazy bod] prefHeader = maybeToList . prefAppliedHeader $ Preferences Nothing Nothing preferCount preferTransaction Nothing preferHandling preferTimezone Nothing [] headers = [ contentRange diff --git a/test/spec/Feature/Query/RangeSpec.hs b/test/spec/Feature/Query/RangeSpec.hs index 5c2541877..427c64f65 100644 --- a/test/spec/Feature/Query/RangeSpec.hs +++ b/test/spec/Feature/Query/RangeSpec.hs @@ -126,7 +126,8 @@ spec = do "hint":null }|] { matchStatus = 416 - , matchHeaders = ["Content-Range" <:> "*/0"] + , matchHeaders = [ "Content-Range" <:> "*/0" + , "Content-Length" <:> "144"] } it "refuses a range requesting start past last item" $ @@ -288,7 +289,8 @@ spec = do "hint":null }|] { matchStatus = 416 - , matchHeaders = ["Content-Range" <:> "*/0"] + , matchHeaders = [ "Content-Range" <:> "*/0" + , "Content-Length" <:> "144"] } it "refuses a range requesting start past last item" $ @@ -470,7 +472,8 @@ spec = do "hint":null }|] { matchStatus = 416 - , matchHeaders = ["Content-Range" <:> "*/0"] + , matchHeaders = [ "Content-Range" <:> "*/0" + , "Content-Length" <:> "144"] } it "refuses a range requesting start past last item" $