From ccd478a82acc617a02f62d110947624619f1cb3c Mon Sep 17 00:00:00 2001 From: mat105 Date: Wed, 19 Oct 2022 13:33:35 -0300 Subject: [PATCH] feat: Generate a copy of json_fields before adding message We had a problem where we wanted to log a payload to another service via "json_fields", however, the logging handler added the key "message" to the payload so we started having errors. I propose to generate a copy of the json_fields instead of using the user supplied one. --- google/cloud/logging_v2/handlers/handlers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/google/cloud/logging_v2/handlers/handlers.py b/google/cloud/logging_v2/handlers/handlers.py index f6fa90d71..28960ae71 100644 --- a/google/cloud/logging_v2/handlers/handlers.py +++ b/google/cloud/logging_v2/handlers/handlers.py @@ -252,6 +252,7 @@ def _format_and_parse_message(record, formatter_handler): pass # if json_fields was set, create a dictionary using that if passed_json_fields and isinstance(passed_json_fields, collections.abc.Mapping): + passed_json_fields = passed_json_fields.copy() if message != "None": passed_json_fields["message"] = message return passed_json_fields