Visitar URL original
gh-103008: Report invalid keys in logging.config.dictConfig() by gaogaotiantian · Pull Request #103013 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260624065100/https://github.com/python/cpython/pull/103013
Skip to content
/ cpython Public

gh-103008: Report invalid keys in logging.config.dictConfig()#103013

Closed
gaogaotiantian wants to merge 3 commits into
python:mainfrom
gaogaotiantian:fix-issue-103008
Closed

gh-103008: Report invalid keys in logging.config.dictConfig()#103013
gaogaotiantian wants to merge 3 commits into
python:mainfrom
gaogaotiantian:fix-issue-103008

Conversation

@gaogaotiantian

@gaogaotiantian gaogaotiantian commented Mar 24, 2023 •

Copy link
Copy Markdown
Member

Currently if an invalid key is provided, it'll just pass silently. This could be confusing to users when they thought they had the correct key name, or they just had a typo.

As the dict SCHEMA is well-defined, and there should be no extra keys in many config fields, we should report the invalid keys so the users can realize that when they try to config the logging.

@gaogaotiantian

Copy link
Copy Markdown
Member Author

Hi @vsajip, could you take a look at this PR when you have some time? Thanks!

Comment thread Lib/logging/config.py
config['()'] = factory
result = self.configure_custom(config)
else:
self._check_config_keys(config, ('format', 'datefmt', 'style', 'validate', 'class'))

@aisk aisk Feb 21, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since key in tuple() is O(n) and key in set() is O(1), maybe we can change the tuple to a set, to obtain a potential performance benefit.

Suggested change
self._check_config_keys(config, ('format', 'datefmt', 'style', 'validate', 'class'))
self._check_config_keys(config, {'format', 'datefmt', 'style', 'validate', 'class'})

Comment thread Lib/logging/config.py

def configure_logger(self, name, config, incremental=False):
"""Configure a non-root logger from a dictionary."""
self._check_config_keys(config, ('level', 'propagate', 'filters', 'handlers'))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
self._check_config_keys(config, ('level', 'propagate', 'filters', 'handlers'))
self._check_config_keys(config, {'level', 'propagate', 'filters', 'handlers'})

@@ -0,0 +1 @@
Report invalid keys in logging.config.dictConfig()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Report invalid keys in logging.config.dictConfig()
Report invalid keys in :func:`logging.config.dictConfig()`.

Comment thread Lib/test/test_logging.py
['bufferGlobal', 'fileGlobal'])

def test_invalid_key(self):
with self.assertRaises(ValueError):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you check the error message as well?

I would prefer to declare config_invalid_key here, instead of 400 lines from here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can do that, but there's an unsolved discussion in the issue #103008 and I don't know if we are pushing this forward.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Check the current error message. It can be updated later.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 12, 2026
@vstinner

Copy link
Copy Markdown
Member

The PR is idle for 2 years and my review has not been addressed. I close the PR.

@vstinner vstinner closed this Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants