Handle illegal JSON casting in hdb_catalog.insert_event_log
(close #8498)
#10677
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Changelog
Component : server
Type: bugfix
Product: community-edition
Short Changelog
Long Changelog
If a Hasura Event Trigger is attached to a table, changes to that table will call the
hdb_catalog.insert_event_log
function to insert the row’s payload into thehdb_catalog.event_logs
table.This function enriches the payload with information about the user via
current_setting('hasura.user', 't')
. It then builds a JSON object with this value—along with the changed row, operation, tracecontext, etc)—and attempts to insert this for thehdb_catalog.event_logs.payload
JSON column. This creates an implicit casting to JSON.This assumes that
current_setting('hasura.user', 't')
will always return JSON or NULL. This is not a safe assumption.Consider the following:
set_config(
hasura.user, 'something', 't')
, commitshdb_catalog.insert_event_log()
is calledcurrent_setting('hasura.user', 't')
to a json columnThis makes Postgres throw an error. The call to
current_setting('hasura.user', 't')
will return an empty string instead of NULL because of the modification made in the transaction[1].There are legitimate reasons why someone may set
hasura.user
viaset_config
-- the biggest one is so that it can be grabbed for the audit table as described in Hasura's documentation. Queries that go though Hasura will have this information attached. But queries made directly to the database will not. In the latter case, we may still want the information available to the audit log function. And therefore need set thehasura.user
manually.[1] The effect of
set_config
is accepted behavior in Postgres and the recommendation is that it should be handled by callers.Related Issues
#8498
Solution and Design
Steps to test and verify
hasura.user
in a transactionLimitations, known bugs & workarounds
Server checklist
Catalog upgrade
Does this PR change Hasura Catalog version?
Metadata
Does this PR add a new Metadata feature?
run_sql
auto manages the new metadata through schema diffing?run_sql
auto manages the definitions of metadata on renaming?export_metadata
/replace_metadata
supports the new metadata added?GraphQL
Breaking changes
No Breaking changes
There are breaking changes:
Metadata API
Existing
query
types:args
payload which is not backward compatibleJSON
schemaGraphQL API
Schema Generation:
NamedType
Schema Resolve:-
null
value for any input fieldsLogging
JSON
schema has changedtype
names have changed