Skip to content

Commit 9ad969e

Browse files
committed
fix: schema cache dump missing RPC transaction isolation level
Fixes #5079. Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
1 parent 63a2267 commit 9ad969e

4 files changed

Lines changed: 68 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file. From versio
2525
- If the schema cache fails to reload, PostgREST will no longer stop serving requests and will continue doing so in a "best effort" basis by @mkleczek in #4873 #4869
2626
- Stop reporting 503s errors unnecessarily while the schema cache is loading at startup by @mkleczek in #4880
2727
- Fix responding with `Something went wrong` on Admin server when under EMFILE by @mkleczek in #5077
28+
- Fix schema cache dump missing RPC transaction isolation level by @taimoorzaeem in #5079
2829

2930
### Changed
3031

src/library/PostgREST/SchemaCache/Routine.hs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
{-# LANGUAGE DeriveAnyClass #-}
2-
{-# LANGUAGE DeriveGeneric #-}
1+
{-# LANGUAGE DeriveAnyClass #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE StandaloneDeriving #-}
4+
{-# OPTIONS_GHC -fno-warn-orphans #-}
35

46
module PostgREST.SchemaCache.Routine
57
( PgType(..)
@@ -20,7 +22,6 @@ module PostgREST.SchemaCache.Routine
2022
, MediaHandler(..)
2123
) where
2224

23-
import Data.Aeson ((.=))
2425
import qualified Data.Aeson as JSON
2526
import qualified Data.HashMap.Strict as HM
2627
import qualified Hasql.Transaction.Sessions as SQL
@@ -30,7 +31,6 @@ import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..),
3031
RelIdentifier (..), Schema,
3132
TableName)
3233

33-
3434
import Protolude
3535

3636
data PgType
@@ -62,20 +62,11 @@ data Routine = Function
6262
, pdIsoLvl :: Maybe SQL.IsolationLevel
6363
, pdFuncSettings :: FuncSettings
6464
}
65-
deriving (Eq, Show, Generic)
66-
-- need to define JSON manually bc SQL.IsolationLevel doesn't have a JSON instance(and we can't define one for that type without getting a compiler error)
67-
instance JSON.ToJSON Routine where
68-
toJSON (Function sch nam desc params ret vol hasVar _ sets) = JSON.object
69-
[
70-
"pdSchema" .= sch
71-
, "pdName" .= nam
72-
, "pdDescription" .= desc
73-
, "pdParams" .= JSON.toJSON params
74-
, "pdReturnType" .= JSON.toJSON ret
75-
, "pdVolatility" .= JSON.toJSON vol
76-
, "pdHasVariadic" .= JSON.toJSON hasVar
77-
, "pdFuncSettings" .= JSON.toJSON sets
78-
]
65+
deriving (Eq, Show, Generic, JSON.ToJSON)
66+
67+
-- SQL.IsolationLevel doesn't have a default ToJSON instance, so we derive it.
68+
deriving instance Generic SQL.IsolationLevel
69+
deriving instance JSON.ToJSON SQL.IsolationLevel
7970

8071
data RoutineParam = RoutineParam
8172
{ ppName :: Text

test/io/__snapshots__/test_cli/test_schema_cache_snapshot[dbRoutines].yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- - statement_timeout
66
- 10s
77
pdHasVariadic: false
8+
pdIsoLvl: null
89
pdName: rpc_with_two_hoisted
910
pdParams: []
1011
pdReturnType:
@@ -23,6 +24,7 @@
2324
- - pdDescription: null
2425
pdFuncSettings: []
2526
pdHasVariadic: false
27+
pdIsoLvl: null
2628
pdName: terminate_pgrst
2729
pdParams:
2830
- ppName: appname
@@ -45,6 +47,7 @@
4547
- - pdDescription: null
4648
pdFuncSettings: []
4749
pdHasVariadic: false
50+
pdIsoLvl: null
4851
pdName: default_isolation_level
4952
pdParams: []
5053
pdReturnType:
@@ -62,6 +65,7 @@
6265
- - pdDescription: null
6366
pdFuncSettings: []
6467
pdHasVariadic: false
68+
pdIsoLvl: null
6569
pdName: change_db_schema_and_full_reload
6670
pdParams:
6771
- ppName: schemas
@@ -84,6 +88,7 @@
8488
- - pdDescription: null
8589
pdFuncSettings: []
8690
pdHasVariadic: false
91+
pdIsoLvl: null
8792
pdName: set_statement_timeout
8893
pdParams:
8994
- ppName: role
@@ -111,6 +116,7 @@
111116
- - pdDescription: null
112117
pdFuncSettings: []
113118
pdHasVariadic: false
119+
pdIsoLvl: null
114120
pdName: notify_pgrst
115121
pdParams: []
116122
pdReturnType:
@@ -128,6 +134,7 @@
128134
- - pdDescription: null
129135
pdFuncSettings: []
130136
pdHasVariadic: false
137+
pdIsoLvl: null
131138
pdName: migrate_function
132139
pdParams: []
133140
pdReturnType:
@@ -145,6 +152,7 @@
145152
- - pdDescription: null
146153
pdFuncSettings: []
147154
pdHasVariadic: false
155+
pdIsoLvl: null
148156
pdName: change_role_statement_timeout
149157
pdParams:
150158
- ppName: timeout
@@ -167,6 +175,7 @@
167175
- - pdDescription: null
168176
pdFuncSettings: []
169177
pdHasVariadic: false
178+
pdIsoLvl: null
170179
pdName: reset_max_rows_config
171180
pdParams: []
172181
pdReturnType:
@@ -184,6 +193,7 @@
184193
- - pdDescription: null
185194
pdFuncSettings: []
186195
pdHasVariadic: false
196+
pdIsoLvl: null
187197
pdName: reset_invalid_role_claim_key
188198
pdParams: []
189199
pdReturnType:
@@ -201,6 +211,7 @@
201211
- - pdDescription: null
202212
pdFuncSettings: []
203213
pdHasVariadic: false
214+
pdIsoLvl: null
204215
pdName: get_postgres_version
205216
pdParams: []
206217
pdReturnType:
@@ -218,6 +229,7 @@
218229
- - pdDescription: null
219230
pdFuncSettings: []
220231
pdHasVariadic: false
232+
pdIsoLvl: null
221233
pdName: do_nothing
222234
pdParams: []
223235
pdReturnType:
@@ -235,6 +247,7 @@
235247
- - pdDescription: null
236248
pdFuncSettings: []
237249
pdHasVariadic: false
250+
pdIsoLvl: null
238251
pdName: get_guc_value
239252
pdParams:
240253
- ppName: name
@@ -259,6 +272,7 @@
259272
- - statement_timeout
260273
- 1s
261274
pdHasVariadic: false
275+
pdIsoLvl: null
262276
pdName: one_sec_timeout
263277
pdParams: []
264278
pdReturnType:
@@ -276,6 +290,7 @@
276290
- - pdDescription: null
277291
pdFuncSettings: []
278292
pdHasVariadic: false
293+
pdIsoLvl: null
279294
pdName: reload_pgrst_config
280295
pdParams: []
281296
pdReturnType:
@@ -295,6 +310,7 @@
295310
- - statement_timeout
296311
- 7s
297312
pdHasVariadic: false
313+
pdIsoLvl: null
298314
pdName: rpc_with_one_hoisted
299315
pdParams: []
300316
pdReturnType:
@@ -313,6 +329,7 @@
313329
- - pdDescription: null
314330
pdFuncSettings: []
315331
pdHasVariadic: false
332+
pdIsoLvl: null
316333
pdName: hello
317334
pdParams: []
318335
pdReturnType:
@@ -330,6 +347,7 @@
330347
- - pdDescription: null
331348
pdFuncSettings: []
332349
pdHasVariadic: false
350+
pdIsoLvl: null
333351
pdName: change_db_schemas_config
334352
pdParams: []
335353
pdReturnType:
@@ -347,6 +365,7 @@
347365
- - pdDescription: null
348366
pdFuncSettings: []
349367
pdHasVariadic: false
368+
pdIsoLvl: null
350369
pdName: sleep
351370
pdParams:
352371
- ppName: seconds
@@ -371,6 +390,7 @@
371390
- - default_transaction_isolation
372391
- serializable
373392
pdHasVariadic: false
393+
pdIsoLvl: Serializable
374394
pdName: serializable_isolation_level
375395
pdParams: []
376396
pdReturnType:
@@ -388,6 +408,7 @@
388408
- - pdDescription: null
389409
pdFuncSettings: []
390410
pdHasVariadic: false
411+
pdIsoLvl: null
391412
pdName: drop_change_cats
392413
pdParams: []
393414
pdReturnType:
@@ -405,6 +426,7 @@
405426
- - pdDescription: null
406427
pdFuncSettings: []
407428
pdHasVariadic: false
429+
pdIsoLvl: null
408430
pdName: change_max_rows_config
409431
pdParams:
410432
- ppName: val
@@ -432,6 +454,7 @@
432454
- - pdDescription: null
433455
pdFuncSettings: []
434456
pdHasVariadic: false
457+
pdIsoLvl: null
435458
pdName: invalid_role_claim_key_reload
436459
pdParams: []
437460
pdReturnType:
@@ -449,6 +472,7 @@
449472
- - pdDescription: null
450473
pdFuncSettings: []
451474
pdHasVariadic: false
475+
pdIsoLvl: null
452476
pdName: reset_db_schemas_config
453477
pdParams: []
454478
pdReturnType:
@@ -466,6 +490,7 @@
466490
- - pdDescription: null
467491
pdFuncSettings: []
468492
pdHasVariadic: false
493+
pdIsoLvl: null
469494
pdName: root
470495
pdParams: []
471496
pdReturnType:
@@ -483,6 +508,7 @@
483508
- - pdDescription: null
484509
pdFuncSettings: []
485510
pdHasVariadic: false
511+
pdIsoLvl: null
486512
pdName: create_function
487513
pdParams: []
488514
pdReturnType:
@@ -500,6 +526,7 @@
500526
- - pdDescription: null
501527
pdFuncSettings: []
502528
pdHasVariadic: false
529+
pdIsoLvl: null
503530
pdName: get_pgrst_version
504531
pdParams: []
505532
pdReturnType:
@@ -512,13 +539,34 @@
512539
pdSchema: public
513540
pdVolatility: Volatile
514541

542+
- - qiName: read_committed_isolation_level
543+
qiSchema: public
544+
- - pdDescription: null
545+
pdFuncSettings:
546+
- - default_transaction_isolation
547+
- read committed
548+
pdHasVariadic: false
549+
pdIsoLvl: ReadCommitted
550+
pdName: read_committed_isolation_level
551+
pdParams: []
552+
pdReturnType:
553+
contents:
554+
contents:
555+
qiName: text
556+
qiSchema: pg_catalog
557+
tag: Scalar
558+
tag: Single
559+
pdSchema: public
560+
pdVolatility: Volatile
561+
515562
- - qiName: repeatable_read_isolation_level
516563
qiSchema: public
517564
- - pdDescription: null
518565
pdFuncSettings:
519566
- - default_transaction_isolation
520567
- REPEATABLE READ
521568
pdHasVariadic: false
569+
pdIsoLvl: RepeatableRead
522570
pdName: repeatable_read_isolation_level
523571
pdParams: []
524572
pdReturnType:
@@ -536,6 +584,7 @@
536584
- - pdDescription: null
537585
pdFuncSettings: []
538586
pdHasVariadic: false
587+
pdIsoLvl: null
539588
pdName: get_work_mem
540589
pdParams: []
541590
pdReturnType:
@@ -553,6 +602,7 @@
553602
- - pdDescription: null
554603
pdFuncSettings: []
555604
pdHasVariadic: false
605+
pdIsoLvl: null
556606
pdName: notify_do_nothing
557607
pdParams: []
558608
pdReturnType:
@@ -570,6 +620,7 @@
570620
- - pdDescription: null
571621
pdFuncSettings: []
572622
pdHasVariadic: false
623+
pdIsoLvl: null
573624
pdName: rpc_work_mem
574625
pdParams: []
575626
pdReturnType:
@@ -590,6 +641,7 @@
590641
- - statement_timeout
591642
- 4s
592643
pdHasVariadic: false
644+
pdIsoLvl: null
593645
pdName: four_sec_timeout
594646
pdParams: []
595647
pdReturnType:

test/io/fixtures/schema.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ returns text as $$
165165
$$
166166
language sql set default_transaction_isolation = 'REPEATABLE READ';
167167

168+
create function read_committed_isolation_level()
169+
returns text as $$
170+
select current_setting('transaction_isolation', true);
171+
$$
172+
language sql set default_transaction_isolation = 'read committed';
173+
168174
create or replace function create_function() returns void as $_$
169175
drop function if exists mult_them(int, int);
170176
create or replace function mult_them(a int, b int) returns int as $$

0 commit comments

Comments
 (0)