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.

@taimoorzaeem taimoorzaeem force-pushed the fix/escape-db-pre-config branch 3 times, most recently from 43e90b1 to 4643eaf Compare October 24, 2025 05:59
Copy link
Member

@steve-chavez steve-chavez left a comment

Choose a reason for hiding this comment

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

Tested it manually. Nice work 💯

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 this 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 4643eaf to 3ddb343 Compare October 29, 2025 06:51
@taimoorzaeem taimoorzaeem marked this pull request as ready for review October 29, 2025 06:52
Comment on lines 42 to +47
dumpQi (QualifiedIdentifier s i) =
(if T.null s then mempty else s <> ".") <> i

quoteQi :: QualifiedIdentifier -> Text
quoteQi (QualifiedIdentifier s i) =
(if T.null s then mempty else escapeIdent s <> ".") <> escapeIdent i
Copy link
Member

@steve-chavez steve-chavez Oct 29, 2025

Choose a reason for hiding this comment

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

Just noticed the dumpQi is too similar to quoteQi.

Shouldn't we stay with quoteQi and drop dumpQi?

dumpQi :: QualifiedIdentifier -> Text
dumpQi (QualifiedIdentifier s i) =
(if T.null s then mempty else s <> ".") <> i

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The dumpQi function is used in the config dumping, here:

,("db-pre-config", q . maybe mempty dumpQi . configDbPreConfig)

With quoteQi we set the config to db-pre-config="true", but then get db-pre-config="\"true\"" in the config dump, which is different, right?

Copy link
Member

Choose a reason for hiding this comment

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

Right, on second thought we shouldn't change usage on those other places on this PR.

But we definitely some clarification between dumpQi/quoteQi, even if it's just a comment on the function saying why we have two functions that are so similar. That can be done on another PR.

(if we can stick to a single function that'd be even better)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright. I think we can move dumpQi to Config.hs module because that's the only place it's used. This should eliminate at least some confusion. Done that on #4435.

@steve-chavez steve-chavez merged commit a688878 into PostgREST:main Oct 29, 2025
33 checks passed
@taimoorzaeem taimoorzaeem deleted the fix/escape-db-pre-config branch October 30, 2025 07:15
@taimoorzaeem
Copy link
Collaborator Author

@wolfgangwalther To backport this to v14, we need to first backport #4432 right? Could you please create the backport v14 label? Or we can just do this manually in one PR too.

@wolfgangwalther
Copy link
Member

Could you please create the backport v14 label?

Added that label to the other PR.

@postgrest-ci
Copy link

postgrest-ci bot commented Oct 30, 2025

Successfully created backport PR for v14:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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