Skip to content

fix(logger): empty or unparsable POWERTOOLS_DEV no longer crashes Logger - #8783

Merged
leandrodamascena merged 5 commits into
aws-powertools:developfrom
krishbuilds01:fix/8765-powertools-dev-empty
Nov 14, 2026
Merged

leandrodamascena merged 5 commits into
aws-powertools:developfrom
krishbuilds01:fix/8765-powertools-dev-empty

Conversation

@krishbuilds01

@krishbuilds01 krishbuilds01 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Setting POWERTOOLS_DEV to an empty string crashed Logger while it was being created, because powertools_dev_is_set() passed the raw value to strtobool and the ValueError escaped. An empty value is easy to end up with from a template or a CI variable, so the crash hit every invocation. An invalid value like treu crashed the same way.

This adds one resolver, resolve_bool_env_var, in shared/functions.py. An empty or unparsable value now warns with PowertoolsUserWarning and falls back to the default, as ADR 0006 asks for, and it matches how #8757 handled POWERTOOLS_PARAMETERS_MAX_AGE. The resolver is used by powertools_dev_is_set, powertools_debug_is_set, is_metrics_disabled and the circuit breaker check, which is the scope settled in the issue thread. The two call sites in idempotency are left alone, they belong to #8728. Valid values behave exactly as before.

The new tests fail on develop and pass with this change. I ran the shared functions and metrics unit tests (52 passed), the circuit breaker functional tests (46 passed), the logger and metrics unit tests (38 passed) and the logger functional tests (177 passed), plus ruff and mypy on the changed files.

I used an AI assistant while preparing this change and reviewed the diff and the test results myself before opening it.

closes #8765

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

@boring-cyborg

boring-cyborg Bot commented Nov 9, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 9, 2026

@blacksoxx blacksoxx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reads correct to me; I did not run the tests here.

The scope matches what leandrodamascena settled on #8765: one resolver in shared/functions.py, used from powertools_dev_is_set, powertools_debug_is_set, is_metrics_disabled and the circuit breaker, with the two idempotency call sites left for #8728. A missing variable still returns the default without a warning, an empty or unparsable one warns with PowertoolsUserWarning and falls back, and valid values go through strtobool unchanged, so existing behaviour holds. The Logger and circuit breaker tests go through the public API, and closes #8765 sits on its own line.

Validation: read the diff at 6505f99 against base 9348364 and the four call sites on develop. Not run: pytest, mypy, ruff.

@krishbuilds01

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review, and for checking the call sites too. Let me know if anything else needs a look.

@leandrodamascena leandrodamascena added this to the 3.41.0 milestone Nov 10, 2026

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @krishbuilds01! This is what I had in mind on #8765. I ran logger, metrics and circuit breaker on top of develop and it's all green. Once this is in I'll make #8734 use your resolver too, so we don't end up with two of them. Goes out in 3.41.0, no need to rebase, you'll be in the release notes.

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 14, 2026

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving after pushing the regenerated agent skill references, nothing else changed.

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.18%. Comparing base (5f7bd1c) to head (5a4bb58).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8783   +/-   ##
========================================
  Coverage    97.18%   97.18%           
========================================
  Files          323      323           
  Lines        16546    16555    +9     
  Branches      1495     1496    +1     
========================================
+ Hits         16080    16089    +9     
  Misses         326      326           
  Partials       140      140           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena
leandrodamascena merged commit b0d3a3c into aws-powertools:develop Nov 14, 2026
14 checks passed
@boring-cyborg

boring-cyborg Bot commented Nov 14, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@powertools-for-aws-oss-automation

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@krishbuilds01

Copy link
Copy Markdown
Contributor Author

Thanks Leandro, really appreciate the review and the guidance on this one. Happy it is going out in 3.41.0.

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

Labels

commons metrics size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: POWERTOOLS_DEV set to an empty string crashes Logger initialization

3 participants