Skip to content

fix(logger): make level and msg positional-only in _log - #8938

Open
azmi2409 wants to merge 1 commit into
aws-powertools:developfrom
azmi2409:fix-8926-logger-level-kwarg
Open

azmi2409 wants to merge 1 commit into
aws-powertools:developfrom
azmi2409:fix-8926-logger-level-kwarg

Conversation

@azmi2409

@azmi2409 azmi2409 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Issue number: closes #8926

Summary

Changes

Logger._log() now takes level and msg as positional-only parameters, so a caller keyword named level flows into the extra keys again instead of colliding with the internal parameter. All internal callers already pass both positionally. The emitted level field keeps the log level, since level is a reserved key.

User experience

Before, logger.info("order placed", level="gold") raised TypeError: Logger._log() got multiple values for argument 'level' on develop since #8871. After, it emits the log line as it did before #8871.

Verification

I reproduced the issue with the snippet from the report and confirmed the TypeError before the fix and a normal log line after it. I added test_logger_level_as_arbitrary_kwarg, which logs with level="gold" and asserts the emitted line has level INFO and the message. Without the fix the test fails with the TypeError; with the fix it passes.

Focused tests, run by me:

pytest tests/functional/logger/required_dependencies/test_logger.py -q
123 passed

ruff check and ruff format --check pass on the changed files. No docs change: the fix restores the behavior from before #8871. I used an AI assistant to write this PR, and I ran the verification above myself.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@azmi2409
azmi2409 requested a review from a team as a code owner December 1, 2026 13:52
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 1, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logger size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Logger raises TypeError when a log call receives a "level" keyword argument

1 participant