8000 Log formatting with %s now can't output dicts · Issue #4267 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content
Log formatting with %s now can't output dicts #4267
Closed
@thatch

Description

@thatch

How do you use Sentry?

Self-hosted/on-premise

Version

2.23.0+

Steps to Reproduce

We've observed cases in open source where a dict is passed positionally to a logging call. A recent change in sentry means that params loses its dict-ness and is only keys by the time it gets to before_send. This can result in "format requires a mapping" or "not all arguments converted during string formatting" exceptions.

Use the following script: repro.txt

We're fairly certain that this comes from the change in 4c9731b which iterates the dict giving only the keys.

Examples where this pattern is used:

Expected Result

Run it with sentry-sdk==2.22.0 and it works fine:

$ python repro.py                  
INFO:test-logger:test {'hello': 'world', 'foo': 'bar'}
INFO:test-logger:test world

Actual Result

If you run it with sentry-sdk==2.23.1 or newer, it's broken:

$ python repro.py
INFO:test-logger:test {'hello': 'world', 'foo': 'bar'}
WARNING:sentrybugrepro:Failed to set formatted message for '{'message': 'test %s', 'params': ['hello', 'foo']}'. exception: TypeError('not all arguments converted during string formatting')
INFO:test-logger:test world
WARNING:sentrybugrepro:Failed to set formatted message for '{'message': 'test %(hello)s', 'params': ['hello', 'foo']}'. exception: TypeError('format requires a mapping')

Metadata

Metadata

Labels

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0