postgrest
postgrest copied to clipboard
Failed resource embedding opens an empty transaction
$ PGRST_DB_ANON_ROLE='postgrest_test_anonymous' postgrest-with-postgresql-14 postgrest-run
curl 'localhost:3000/projects?select=*,wrong(*)'
{"code":"PGRST200","details":null,"hint":"Verify that 'projects' and 'wrong' exist in the schema 'test' and that there is a foreign key relationship between them. If a new relationship was created, try reloading the schema cache.","message":"Could not find a relationship between 'projects' and 'wrong' in the schema cache"}
2022-08-15 18:20:14.212 -05 [679420] LOG: execute 0: BEGIN ISOLATION LEVEL READ COMMITTED READ ONLY
2022-08-15 18:20:14.213 -05 [679420] LOG: execute 7: select set_config($1, $2, true), set_config($3, $4, true), set_config($5, $6, true), set_config($7, $8, true), set_config($9, $10, true),
set_config($11, $12, true), set_config($13, $14, true)
2022-08-15 18:20:14.213 -05 [679420] DETAIL: parameters: $1 = 'search_path', $2 = '"test", "extensions"', $3 = 'role', $4 = 'postgrest_test_anonymous', $5 = 'request.jwt.claims', $6 = '{"role
":"postgrest_test_anonymous"}', $7 = 'request.method', $8 = 'GET', $9 = 'request.path', $10 = '/projects', $11 = 'request.headers', $12 = '{"host":"localhost:3000","accept":"*/*","user-agent":
"curl/7.81.0"}', $13 = 'request.cookies', $14 = '{}'
2022-08-15 18:20:14.220 -05 [679420] LOG: execute 1: COMMIT
For solving this we need a refactor on DbRequestBuilder.hs/App.hs.
I was thinking that ideally the phases/modules in the codebase should be like:
ApiRequest(doesn't open a tx, doesn't need schema cache) ->
DbRequestBuilder(doesn't open a tx, needs schema cache) ->
QueryBuilder/Statements (opens a tx, needs schema cache) ->
DB
DbRequestBuilder needs renaming
Edit: DbRequestbuilder was renamed to Plan https://github.com/PostgREST/postgrest/pull/2497