gh-103008: Report invalid keys in logging.config.dictConfig()#103013
gh-103008: Report invalid keys in logging.config.dictConfig()#103013gaogaotiantian wants to merge 3 commits into
Conversation
|
Hi @vsajip, could you take a look at this PR when you have some time? Thanks! |
| config['()'] = factory | ||
| result = self.configure_custom(config) | ||
| else: | ||
| self._check_config_keys(config, ('format', 'datefmt', 'style', 'validate', 'class')) |
There was a problem hiding this comment.
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.
| self._check_config_keys(config, ('format', 'datefmt', 'style', 'validate', 'class')) | |
| self._check_config_keys(config, {'format', 'datefmt', 'style', 'validate', 'class'}) |
|
|
||
| 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')) |
There was a problem hiding this comment.
| 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() | |||
There was a problem hiding this comment.
| Report invalid keys in logging.config.dictConfig() | |
| Report invalid keys in :func:`logging.config.dictConfig()`. |
| ['bufferGlobal', 'fileGlobal']) | ||
|
|
||
| def test_invalid_key(self): | ||
| with self.assertRaises(ValueError): |
There was a problem hiding this comment.
Can you check the error message as well?
I would prefer to declare config_invalid_key here, instead of 400 lines from here.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Check the current error message. It can be updated later.
|
This PR is stale because it has been open for 30 days with no activity. |
|
The PR is idle for 2 years and my review has not been addressed. I close the PR. |


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.