Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interpolation in filtered log calls #478

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ This prevents crashes if something different than a string is passed for the *ev
[#475](https://github.com/hynek/structlog/pull/475)


### Fixed

- String interpolation doesn't cause crashes in filtered log call anymore.
[#478](https://github.com/hynek/structlog/pull/478)


## [22.2.0](https://github.com/hynek/structlog/compare/22.1.0...22.2.0) - 2022-11-19

### Deprecated
Expand Down
4 changes: 2 additions & 2 deletions src/structlog/_log_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def add_log_level(
return event_dict


def _nop(self: Any, event: str, **kw: Any) -> Any:
def _nop(self: Any, event: str, *args: Any, **kw: Any) -> Any:
return None


async def _anop(self: Any, event: str, **kw: Any) -> Any:
async def _anop(self: Any, event: str, *args: Any, **kw: Any) -> Any:
return None


Expand Down
16 changes: 16 additions & 0 deletions tests/test_log_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ async def test_async_one_below(self, bl, cl):

assert [] == cl.calls

def test_filtered_interp(self, bl, cl):
"""
Passing interpolation args works if the log entry is filtered out.
"""
bl.debug("hello %s!", "world")

assert [] == cl.calls

async def test_async_filtered_interp(self, bl, cl):
"""
Passing interpolation args works if the log entry is filtered out.
"""
await bl.adebug("hello %s!", "world")

assert [] == cl.calls

def test_no_args(self, bl, cl):
"""
If no args are passed, don't attempt intepolation.
Expand Down