Logging the literal string "None" is silently dropped (payload becomes empty)
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 85/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- python
- Bereich
- observability
Rechercherichtung
Beginne in google/cloud/logging_v2/handlers/handlers.py bei _format_and_parse_message und führe dann die bereitgestellte LogRecord-Reproduktion für "None", "hello" und "" aus. Erledigt ist es, wenn die Literalzeichenfolge "None" in der geparsten Payload erhalten bleibt, während die bestehenden Fälle ihre erwarteten Ergebnisse behalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
- I determined this is the correct repository in which to report this bug.
Summary of the issue
Context
Using CloudLoggingHandler / StructuredLogHandler via the Python standard logging module, I logged the string "None" (e.g. logging.getLogger().info("None")).
Expected Behavior:
The log entry payload should contain the text "None", just like any other string.
Actual Behavior:
The message is silently dropped: the parsed payload becomes None (empty), so the log content disappears.
API client name and version
google-cloud-logging v3.15.0 (also present on current main)
Reproduction steps: code
import logging
from google.cloud.logging_v2.handlers import handlers as H
class FakeHandler(logging.Handler):
pass
h = FakeHandler()
h.setFormatter(logging.Formatter())
def rec(msg):
return logging.LogRecord("n", logging.INFO, "p", 1, msg, (), None)
for msg in ["None", "hello", ""]:
print(repr(msg), "->", repr(H._format_and_parse_message(rec(msg), h)))
Reproduction steps: actual results
'None' -> None # the user's message is dropped
'hello' -> 'hello'
'' -> ''
Reproduction steps: expected results
'None' -> 'None' # the literal string should be preserved
'hello' -> 'hello'
'' -> ''
OS & version + platform
Any (logic bug, platform-independent)
Python environment
Python 3.12
Additional context
Root cause in google/cloud/logging_v2/handlers/handlers.py (_format_and_parse_message):
if message != "None":
passed_json_fields["message"] = message
...
return message if message != "None" else None
The intent appears to be detecting a record whose msg is the Python object None (which logging.Formatter renders as the string "None"). But comparing the formatted string against "None" also matches a legitimate user message of the literal text "None", dropping it. Detecting emptiness from record.msg is None (before formatting) rather than from the formatted output would avoid the false positive.
- Vorherrschende Sprache
- Python
- Sterne
- 5.4k
- Forks
- 1.8k
- Ø Merge
- 1 T. 17 Std.
- Gemergte PRs (30 T.)
- 93
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus googleapis/google-cloud-python
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
googleapis/google-cloud-python#18428 ·
-
priority: p2 type: bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
googleapis/google-cloud-python#18375 · 1 Kommentar ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 76/100
googleapis/google-cloud-python#18339 ·
-
auth priority: p2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
googleapis/google-cloud-python#18315 ·
-
priority: p2 type: bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
googleapis/google-cloud-python#18260 ·
Alle Issues in googleapis/google-cloud-python
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100