diff --git a/server/src-lib/Hasura/Backends/Postgres/DDL/RunSQL.hs b/server/src-lib/Hasura/Backends/Postgres/DDL/RunSQL.hs index 94788ce62a3..301d5b86dd0 100644 --- a/server/src-lib/Hasura/Backends/Postgres/DDL/RunSQL.hs +++ b/server/src-lib/Hasura/Backends/Postgres/DDL/RunSQL.hs @@ -14,6 +14,7 @@ module Hasura.Backends.Postgres.DDL.RunSQL ( runRunSQL, RunSQL (..), + isReadOnly, isSchemaCacheBuildRequiredRunSQL, ) where @@ -80,8 +81,8 @@ instance FromJSON RunSQL where rSource <- o .:? "source" .!= defaultSource rCascade <- o .:? "cascade" .!= False rCheckMetadataConsistency <- o .:? "check_metadata_consistency" - isReadOnly <- o .:? "read_only" .!= False - let rTxAccessMode = if isReadOnly then PG.ReadOnly else PG.ReadWrite + readOnly <- o .:? "read_only" .!= False + let rTxAccessMode = if readOnly then PG.ReadOnly else PG.ReadWrite pure RunSQL {..} instance ToJSON RunSQL where @@ -120,6 +121,12 @@ isSchemaCacheBuildRequiredRunSQL RunSQL {..} = "\\balter\\b|\\bdrop\\b|\\breplace\\b|\\bcreate function\\b|\\bcomment on\\b" ) +isReadOnly :: RunSQL -> Bool +isReadOnly runsql = + case rTxAccessMode runsql of + PG.ReadOnly -> True + PG.ReadWrite -> False + {- Note [Checking metadata consistency in run_sql] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SQL queries executed by run_sql may change the Postgres schema in arbitrary diff --git a/server/src-lib/Hasura/Server/API/V2Query.hs b/server/src-lib/Hasura/Server/API/V2Query.hs index e739f20aca7..d5445501fc5 100644 --- a/server/src-lib/Hasura/Server/API/V2Query.hs +++ b/server/src-lib/Hasura/Server/API/V2Query.hs @@ -204,9 +204,9 @@ queryModifiesUserDB = \case RQUpdate _ -> True RQDelete _ -> True RQCount _ -> False - RQRunSql _ -> True - RQCitusRunSql _ -> True - RQCockroachRunSql _ -> True + RQRunSql runsql -> not (Postgres.isReadOnly runsql) + RQCitusRunSql runsql -> not (Postgres.isReadOnly runsql) + RQCockroachRunSql runsql -> not (Postgres.isReadOnly runsql) RQMssqlRunSql _ -> True RQMysqlRunSql _ -> True RQBigqueryRunSql _ -> True