Skip to content

Conversation

taimoorzaeem
Copy link
Collaborator

When db-pre-config is accidentally set to a pg reserved word like "true", it fails with a confusing error. The function names should be properly quoted to avoid such errors. This commit resolves the mentioned issue by quoting the pre-config function name.

Closes #4380.

Comment on lines 214 to 217
quotePreConfFunc :: Text -> Text
quotePreConfFunc f = T.intercalate "." $ map escapeIdent $ T.split (== '.') f
where
escapeIdent id = "\"" <> id <> "\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have a helper function for this somewhere already?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

escapeIdent :: Text -> Text
escapeIdent x = "\"" <> T.replace "\"" "\"\"" (trimNullChars x) <> "\""

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromQi :: QualifiedIdentifier -> SQL.Snippet
fromQi t = (if T.null s then mempty else pgFmtIdent s <> ".") <> pgFmtIdent n
where
n = qiName t
s = qiSchema t

We have this, but it gives a Snippet and not Text. Also, the Config/Database.hs module is currently free of Query and SchemaCache modules, so let's not pollute it with that as it would make the dependency graph even weirder.

I think long term solution would be to have our own Prelude as discussed in #1804 (comment). For now I have handled it by quoting it by a new function quoteQi.

@taimoorzaeem taimoorzaeem force-pushed the fix/escape-db-pre-config branch from 6739eef to 05f891a Compare October 23, 2025 06:47
When db-pre-config is accidentally set to a pg reserved word
like "true", it fails with a confusing error. The function
names should be properly quoted to avoid such errors. This commit
resolves the mentioned issue by quoting the pre-config function
name.

Signed-off-by: Taimoor Zaeem <[email protected]>
@taimoorzaeem taimoorzaeem force-pushed the fix/escape-db-pre-config branch from 05f891a to 3468524 Compare October 23, 2025 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Using PGREST_DB_PRE_CONFIG w/out the underlying config function yields a confusing error

3 participants