Skip to content

fix: fix LOGFIRE_IGNORE_NO_CONFIG to prevent warning from LogFireConf…#1379

Merged
alexmojaki merged 6 commits intopydantic:mainfrom
Lftobs:fix/fix-ignore-no-config
Sep 10, 2025
Merged

fix: fix LOGFIRE_IGNORE_NO_CONFIG to prevent warning from LogFireConf…#1379
alexmojaki merged 6 commits intopydantic:mainfrom
Lftobs:fix/fix-ignore-no-config

Conversation

@Lftobs
Copy link
Copy Markdown
Contributor

@Lftobs Lftobs commented Sep 5, 2025

This PR introduces a fix for the issue described in #1331

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@LucasSantos27 LucasSantos27 left a comment

Choose a reason for hiding this comment

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

tip: instead of creating a new commit, you can run git commit --amend to add to the same commit

@Lftobs Lftobs force-pushed the fix/fix-ignore-no-config branch from 76d857a to f2200da Compare September 6, 2025 04:39
Copy link
Copy Markdown
Contributor

@LucasSantos27 LucasSantos27 left a comment

Choose a reason for hiding this comment

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

small fixes, good job!

Comment on lines +1200 to +1201
ignore_no_config_env = os.getenv('LOGFIRE_IGNORE_NO_CONFIG')
ignore_no_config = (ignore_no_config_env == '1') or self.ignore_no_config
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ignore_no_config_env = os.getenv('LOGFIRE_IGNORE_NO_CONFIG')
ignore_no_config = (ignore_no_config_env == '1') or self.ignore_no_config
ignore_no_config_env = os.getenv('LOGFIRE_IGNORE_NO_CONFIG', '')
ignore_no_config = ignore_no_config_env.lower() in ('1', 'true', 't') or self.ignore_no_config

Comment on lines +3497 to +3502
with warnings.catch_warnings(record=True) as warning_list:
warnings.simplefilter('always')
config.warn_if_not_initialized('Should not warn with env var')

logfire_warnings = [w for w in warning_list if issubclass(w.category, LogfireNotConfiguredWarning)]
assert len(logfire_warnings) == 0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
with warnings.catch_warnings(record=True) as warning_list:
warnings.simplefilter('always')
config.warn_if_not_initialized('Should not warn with env var')
logfire_warnings = [w for w in warning_list if issubclass(w.category, LogfireNotConfiguredWarning)]
assert len(logfire_warnings) == 0
config.warn_if_not_initialized('Should not warn with env var')

This is enough, if there was a warning pytest would raise an error.

Comment on lines +3525 to +3529
with warnings.catch_warnings(record=True) as warning_list:
warnings.simplefilter('always')

logfire_warnings = [w for w in warning_list if issubclass(w.category, LogfireNotConfiguredWarning)]
assert len(logfire_warnings) == 0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

again, no need for all this to check for a lack of warnings, but you haven't even got anything here that might emit a warning

Comment on lines +3521 to +3522
logfire_warnings = [w for w in warnings_list if issubclass(w.category, LogfireNotConfiguredWarning)]
assert len(logfire_warnings) == 1
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
logfire_warnings = [w for w in warnings_list if issubclass(w.category, LogfireNotConfiguredWarning)]
assert len(logfire_warnings) == 1
assert len(warnings_list) == 1

if there's a different kind of warning, pytest will raise an error, since you have pytest.warns(LogfireNotConfiguredWarning).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. I have updated the code to include these changes.

@alexmojaki alexmojaki enabled auto-merge (squash) September 10, 2025 09:23
@alexmojaki
Copy link
Copy Markdown
Collaborator

Thanks!

@alexmojaki alexmojaki merged commit d2a8878 into pydantic:main Sep 10, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants