Skip to content

Commit

Permalink
fix: empty row on handler function
Browse files Browse the repository at this point in the history
Closes #3126
  • Loading branch information
steve-chavez committed Dec 20, 2023
1 parent 1680a6e commit 3af63cb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- #3124, Fix table's media type handlers not working for all schemas - @steve-chavez
- #3126, Fix empty row on media type handler function - @steve-chavez

## [12.0.1] - 2023-12-12

Expand Down
3 changes: 2 additions & 1 deletion src/PostgREST/Query/Statements.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ preparePlanRows countQuery =
standardRow :: Bool -> HD.Row ResultSet
standardRow noLocation =
RSStandard <$> nullableColumn HD.int8 <*> column HD.int8
<*> (if noLocation then pure mempty else fmap splitKeyValue <$> arrayColumn HD.bytea) <*> column HD.bytea
<*> (if noLocation then pure mempty else fmap splitKeyValue <$> arrayColumn HD.bytea)
<*> (fromMaybe mempty <$> nullableColumn HD.bytea)
<*> nullableColumn HD.bytea
<*> nullableColumn HD.text
<*> nullableColumn HD.int8
Expand Down
7 changes: 7 additions & 0 deletions test/spec/Feature/Query/CustomMediaSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ spec = describe "custom media types" $ do
, matchHeaders = ["Content-Type" <:> "application/json; charset=utf-8"]
}

it "should not fail when the function doesn't return a row" $ do
request methodGet "/rpc/get_line?id=777" (acceptHdrs "application/vnd.twkb") ""
`shouldRespondWith` ""
{ matchStatus = 200
, matchHeaders = ["Content-Type" <:> "application/vnd.twkb"]
}

context "Proc that returns scalar based on a table" $ do
it "can get an image with Accept: image/png" $ do
r <- request methodGet "/rpc/ret_image" (acceptHdrs "image/png") ""
Expand Down
5 changes: 5 additions & 0 deletions test/spec/fixtures/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3517,6 +3517,11 @@ returns setof test.lines as $$
select * from lines;
$$ language sql;

create or replace function test.get_line (id int)
returns "application/vnd.twkb" as $$
select extensions.st_astwkb(geom)::"application/vnd.twkb" from lines where id = get_line.id;
$$ language sql;

create or replace function test.get_shop_bles ()
returns setof test.shop_bles as $$
select * from shop_bles;
Expand Down

0 comments on commit 3af63cb

Please sign in to comment.