René's URL Explorer Experiment


Title: Crash with google.protobuf.json_format.ParseError: Value '2024-09-23' has unexpected type · Issue #943 · googleapis/python-logging · GitHub

Open Graph Title: Crash with google.protobuf.json_format.ParseError: Value '2024-09-23' has unexpected type · Issue #943 · googleapis/python-logging

X Title: Crash with google.protobuf.json_format.ParseError: Value '2024-09-23' has unexpected type · Issue #943 · googleapis/python-logging

Description: Environment details OS type and version: python:3.11.9-bookworm base image Python version: 3.11.9 pip version: pip 24.0 from /usr/local/lib/python3.11/site-packages/pip (python 3.11) google-cloud-logging version: 3.11.2 Steps to reproduc...

Open Graph Description: Environment details OS type and version: python:3.11.9-bookworm base image Python version: 3.11.9 pip version: pip 24.0 from /usr/local/lib/python3.11/site-packages/pip (python 3.11) google-cloud-l...

X Description: Environment details OS type and version: python:3.11.9-bookworm base image Python version: 3.11.9 pip version: pip 24.0 from /usr/local/lib/python3.11/site-packages/pip (python 3.11) google-cloud-l...

Opengraph URL: https://github.com/googleapis/python-logging/issues/943

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash with google.protobuf.json_format.ParseError: Value '2024-09-23' has unexpected type \u003cclass 'datetime.date'\u003e","articleBody":"#### Environment details\r\n\r\n  - OS type and version: `python:3.11.9-bookworm` base image\r\n  - Python version: `3.11.9`\r\n  - pip version: `pip 24.0 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)`\r\n  - `google-cloud-logging` version: `3.11.2`\r\n\r\n#### Steps to reproduce\r\n\r\nTrying to send down a dict that has a DateTime property blows the library up with a `google.protobuf.json_format.ParseError`\r\n\r\nI guess I could work around it manually and convert it to a string myself, but the bigger issue is that I wouldn't expect a logging library to crash my application.\r\n\r\nIdeally the library should handle anything thrown at it with a best effort string conversion (even if it's just a useless class instance identity or anything), but at the very least have a way to log its own error rather than throwing an unhandled exception? Or are end users expected to wrap it in try / except and handle certain errors? Or is there a way to give the library a custom JSON parser?\r\n\r\n#### Code example\r\n\r\n```python\r\nfrom datetime import datetime\r\nfrom google.cloud import logging\r\n\r\nlogging_client = logging.Client()\r\nlogging_client.setup_logging()\r\n\r\nmy_dict = {\"my_date\": datetime.now()}\r\n\r\nlogging_client.logger(\"default\").log_struct({\"message\": \"message\", \"my_dict\": my_dict}, severity=\"INFO\")\r\n```\r\n\r\nI thought maybe using the `logging` std lib might make a difference but that also crashes:\r\n\r\n```python\r\nimport logging\r\nfrom datetime import datetime\r\nfrom google.cloud import logging as gcloud_logging\r\n\r\nlogging_client = gcloud_logging.Client()\r\nlogging_client.setup_logging()\r\n\r\ndata_dict = {\"my_date\": datetime.now()}\r\nlogging.info(\"message field\", extra={\"json_fields\": data_dict})\r\n\r\n\u003e\u003e\u003e Failed to submit 1 logs.\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 600, in _ConvertFieldValuePair\r\n    self.ConvertMessage(value, sub_message, '{0}.{1}'.format(path, name))\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 485, in ConvertMessage\r\n    methodcaller(_WKTJSONMETHODS[full_name][1], value, message, path)(self)\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 704, in _ConvertStructMessage\r\n    self._ConvertValueMessage(value[key], message.fields[key],\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 682, in _ConvertValueMessage\r\n    raise ParseError('Value {0} has unexpected type {1} at {2}'.format(\r\ngoogle.protobuf.json_format.ParseError: Value 2024-09-23 17:55:34.185216 has unexpected type \u003cclass 'datetime.datetime'\u003e at LogEntry.jsonPayload.my_date\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/handlers/transports/background_thread.py\", line 115, in _safely_commit_batch\r\n    batch.commit()\r\n  File \"/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/logger.py\", line 468, in commit\r\n    client.logging_api.write_entries(\r\n  File \"/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/_gapic.py\", line 154, in write_entries\r\n    log_entry_pbs = [_log_entry_mapping_to_pb(entry) for entry in entries]\r\n                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/_gapic.py\", line 154, in \u003clistcomp\u003e\r\n    log_entry_pbs = [_log_entry_mapping_to_pb(entry) for entry in entries]\r\n                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/_gapic.py\", line 557, in _log_entry_mapping_to_pb\r\n    ParseDict(mapping, entry_pb)\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 446, in ParseDict\r\n    parser.ConvertMessage(js_dict, message, '')\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 487, in ConvertMessage\r\n    self._ConvertFieldValuePair(value, message, path)\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 616, in _ConvertFieldValuePair\r\n    raise ParseError(str(e)) from e\r\ngoogle.protobuf.json_format.ParseError: Value 2024-09-23 17:55:34.185216 has unexpected type \u003cclass 'datetime.datetime'\u003e at LogEntry.jsonPayload.my_date\r\n```\r\n\r\n#### Stack trace\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 600, in _ConvertFieldValuePair\r\n    self.ConvertMessage(value, sub_message, '{0}.{1}'.format(path, name))\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 485, in ConvertMessage\r\n    methodcaller(_WKTJSONMETHODS[full_name][1], value, message, path)(self)\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 704, in _ConvertStructMessage\r\n    self._ConvertValueMessage(value[key], message.fields[key],\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 670, in _ConvertValueMessage\r\n    self._ConvertStructMessage(value, message.struct_value, path)\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 704, in _ConvertStructMessage\r\n    self._ConvertValueMessage(value[key], message.fields[key],\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 682, in _ConvertValueMessage\r\n    raise ParseError('Value {0} has unexpected type {1} at {2}'.format(\r\ngoogle.protobuf.json_format.ParseError: Value 2024-09-23 17:24:50.706366 has unexpected type \u003cclass 'datetime.datetime'\u003e at LogEntry.jsonPayload.my_dict.my_date\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\n  File \"/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/logger.py\", line 220, in log_struct\r\n    self._do_log(client, StructEntry, info, **kw)\r\n  File \"/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/logger.py\", line 169, in _do_log\r\n    client.logging_api.write_entries(entries, partial_success=True)\r\n  File \"/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/_gapic.py\", line 154, in write_entries\r\n    log_entry_pbs = [_log_entry_mapping_to_pb(entry) for entry in entries]\r\n                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/_gapic.py\", line 154, in \u003clistcomp\u003e\r\n    log_entry_pbs = [_log_entry_mapping_to_pb(entry) for entry in entries]\r\n                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/_gapic.py\", line 557, in _log_entry_mapping_to_pb\r\n    ParseDict(mapping, entry_pb)\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 446, in ParseDict\r\n    parser.ConvertMessage(js_dict, message, '')\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 487, in ConvertMessage\r\n    self._ConvertFieldValuePair(value, message, path)\r\n  File \"/usr/local/lib/python3.11/site-packages/google/protobuf/json_format.py\", line 616, in _ConvertFieldValuePair\r\n    raise ParseError(str(e)) from e\r\ngoogle.protobuf.json_format.ParseError: Value 2024-09-23 17:24:50.706366 has unexpected type \u003cclass 'datetime.datetime'\u003e at LogEntry.jsonPayload.my_dict.my_date```\r\n","author":{"url":"https://github.com/daaain","@type":"Person","name":"daaain"},"datePublished":"2024-09-23T17:34:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/943/python-logging/issues/943"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:a43f3f25-c354-04d8-bd3e-34506ca6e173
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8522:1E2E76:D81372:1275A73:6A4C5F4C
html-safe-nonce7a1596bc845c9dee4b374811848045e613c5fe26361a140c33dec5ed01a7c5b8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTIyOjFFMkU3NjpEODEzNzI6MTI3NUE3Mzo2QTRDNUY0QyIsInZpc2l0b3JfaWQiOiIxNjM2Mjk0OTI4NTIxNTE4OTI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac1a11255a5e3669c6210b4ae28a0903cc39847073bed120e44b0716bd5efa2f89
hovercard-subject-tagissue:2543252752
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-logging/943/issue_layout
twitter:imagehttps://opengraph.githubassets.com/3175bbe7f40dd216fac860ee6fc93330e63fb4925668f0b25838a35da08cbfb0/googleapis/python-logging/issues/943
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/3175bbe7f40dd216fac860ee6fc93330e63fb4925668f0b25838a35da08cbfb0/googleapis/python-logging/issues/943
og:image:altEnvironment details OS type and version: python:3.11.9-bookworm base image Python version: 3.11.9 pip version: pip 24.0 from /usr/local/lib/python3.11/site-packages/pip (python 3.11) google-cloud-l...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedaaain
hostnamegithub.com
expected-hostnamegithub.com
None3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c
turbo-cache-controlno-preview
go-importgithub.com/googleapis/python-logging git https://github.com/googleapis/python-logging.git
octolytics-dimension-user_id16785467
octolytics-dimension-user_logingoogleapis
octolytics-dimension-repository_id226992562
octolytics-dimension-repository_nwogoogleapis/python-logging
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id226992562
octolytics-dimension-repository_network_root_nwogoogleapis/python-logging
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release14099438da5379150f15a2892474c7c7e6c0e55e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/googleapis/python-logging/issues/943#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-logging%2Fissues%2F943
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-logging%2Fissues%2F943
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=googleapis%2Fpython-logging
Reloadhttps://github.com/googleapis/python-logging/issues/943
Reloadhttps://github.com/googleapis/python-logging/issues/943
Reloadhttps://github.com/googleapis/python-logging/issues/943
Please reload this pagehttps://github.com/googleapis/python-logging/issues/943
googleapis https://github.com/googleapis
python-logginghttps://github.com/googleapis/python-logging
Notifications https://github.com/login?return_to=%2Fgoogleapis%2Fpython-logging
Fork 59 https://github.com/login?return_to=%2Fgoogleapis%2Fpython-logging
Star 142 https://github.com/login?return_to=%2Fgoogleapis%2Fpython-logging
Code https://github.com/googleapis/python-logging
Issues 0 https://github.com/googleapis/python-logging/issues
Pull requests 0 https://github.com/googleapis/python-logging/pulls
Actions https://github.com/googleapis/python-logging/actions
Projects https://github.com/googleapis/python-logging/projects
Security and quality 0 https://github.com/googleapis/python-logging/security
Insights https://github.com/googleapis/python-logging/pulse
Code https://github.com/googleapis/python-logging
Issues https://github.com/googleapis/python-logging/issues
Pull requests https://github.com/googleapis/python-logging/pulls
Actions https://github.com/googleapis/python-logging/actions
Projects https://github.com/googleapis/python-logging/projects
Security and quality https://github.com/googleapis/python-logging/security
Insights https://github.com/googleapis/python-logging/pulse
Crash with google.protobuf.json_format.ParseError: Value '2024-09-23' has unexpected type https://github.com/googleapis/python-logging/issues/943#top
https://github.com/gkevinzheng
api: loggingIssues related to the googleapis/python-logging API.https://github.com/googleapis/python-logging/issues?q=state%3Aopen%20label%3A%22api%3A%20logging%22
https://github.com/daaain
daaainhttps://github.com/daaain
on Sep 23, 2024https://github.com/googleapis/python-logging/issues/943#issue-2543252752
gkevinzhenghttps://github.com/gkevinzheng
api: loggingIssues related to the googleapis/python-logging API.https://github.com/googleapis/python-logging/issues?q=state%3Aopen%20label%3A%22api%3A%20logging%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.