Skip to content

Commit 23a8ef2

Browse files
Guard RedactUrlQueryParamsFilter against None args
urllib3.connectionpool records can arrive with record.args set to None when another logging filter (e.g. MLflow's SensitiveQueryParamFilter) redacts the message and nulls args before this filter runs. Iterating None raised TypeError. Guard the tuple branch with an explicit None check. Also fix a latent typo in the dict-args branch: record.arg[k] should be record.args[k], which would raise AttributeError whenever a record carried dict args. Fixes #946 Signed-off-by: Jonathan Berthias <jvberthias@gmail.com>
1 parent 13e8af4 commit 23a8ef2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/databricks/sql/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ def __init__(self):
3030
def redact(self, string):
3131
return re.sub(self.pattern, self.mask, str(string))
3232

33-
def filter(self, record):
33+
def filter(self, record: logging.LogRecord):
3434
record.msg = self.redact(str(record.msg))
3535
if isinstance(record.args, dict):
3636
for k in record.args.keys():
3737
record.args[k] = (
3838
self.redact(record.args[k])
39-
if isinstance(record.arg[k], str)
39+
if isinstance(record.args[k], str)
4040
else record.args[k]
4141
)
42-
else:
42+
elif record.args is not None:
4343
record.args = tuple(
4444
(self.redact(arg) if isinstance(arg, str) else arg)
4545
for arg in record.args

0 commit comments

Comments
 (0)