diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ddee6fa..48eeb0c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/structlog/_log_levels.py b/src/structlog/_log_levels.py index 4d497807..6e9fb1af 100644 --- a/src/structlog/_log_levels.py +++ b/src/structlog/_log_levels.py @@ -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 diff --git a/tests/test_log_levels.py b/tests/test_log_levels.py index fff9cce7..2a0e579c 100644 --- a/tests/test_log_levels.py +++ b/tests/test_log_levels.py @@ -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.