Skip to content

Commit d02edd3

Browse files
authored
fix: deep copy config before redaction (#272)
fixes #264 Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
1 parent 318acdc commit d02edd3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

context_chat_backend/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ def redact_config(config: TConfig | TEmbeddingConfig) -> TConfig | TEmbeddingCon
129129
'''
130130
Redact sensitive information from the config for logging
131131
'''
132-
if isinstance(config, TConfig):
133-
em_conf = config.embedding
132+
config_copy = config.model_copy(deep=True)
133+
134+
if isinstance(config_copy, TConfig):
135+
em_conf = config_copy.embedding
134136
else:
135-
em_conf = config
137+
em_conf = config_copy
136138

137139
if em_conf.auth:
138140
if isinstance(em_conf.auth, TEmbeddingAuthApiKey):
@@ -141,4 +143,4 @@ def redact_config(config: TConfig | TEmbeddingConfig) -> TConfig | TEmbeddingCon
141143
em_conf.auth.username = '***REDACTED***'
142144
em_conf.auth.password = '***REDACTED***' # noqa: S105
143145

144-
return config
146+
return config_copy

0 commit comments

Comments
 (0)