-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle current_setting parameters with empty strings in insert_event_log
PR-URL: hasura/graphql-engine-mono#11143 GitOrigin-RevId: a04c8c9d04557817a1249de78ef5c6f915d3e706
- Loading branch information
1 parent
0406058
commit 13dd224
Showing
3 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
CREATE OR REPLACE FUNCTION | ||
hdb_catalog.insert_event_log(schema_name text, table_name text, trigger_name text, op text, row_data json) | ||
RETURNS text AS $$ | ||
DECLARE | ||
id text; | ||
payload json; | ||
session_variables json; | ||
server_version_num int; | ||
trace_context json; | ||
BEGIN | ||
id := gen_random_uuid(); | ||
server_version_num := current_setting('server_version_num'); | ||
IF server_version_num >= 90600 THEN | ||
-- In some cases postgres sets the setting to an empty string, which is not a valid json. | ||
-- NULLIF will convert the empty string to NULL. | ||
-- Ref: https://github.com/hasura/graphql-engine/issues/8498 | ||
session_variables := NULLIF(current_setting('hasura.user', 't'), ''); | ||
trace_context := NULLIF(current_setting('hasura.tracecontext', 't'), ''); | ||
ELSE | ||
BEGIN | ||
session_variables := current_setting('hasura.user'); | ||
EXCEPTION WHEN OTHERS THEN | ||
session_variables := NULL; | ||
END; | ||
BEGIN | ||
trace_context := current_setting('hasura.tracecontext'); | ||
EXCEPTION WHEN OTHERS THEN | ||
trace_context := NULL; | ||
END; | ||
END IF; | ||
payload := json_build_object( | ||
'op', op, | ||
'data', row_data, | ||
'session_variables', session_variables, | ||
'trace_context', trace_context | ||
); | ||
INSERT INTO hdb_catalog.event_log | ||
(id, schema_name, table_name, trigger_name, payload) | ||
VALUES | ||
(id, schema_name, table_name, trigger_name, payload); | ||
RETURN id; | ||
END; | ||
$$ LANGUAGE plpgsql; |