Skip to content

Commit 143d04a

Browse files
author
Andrei Neagu
committed
add optional serializer to fix issues
1 parent 25767ca commit 143d04a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/settings-library/src/settings_library/utils_cli.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ def print_as_envfile(
6767

6868

6969
def print_as_json(
70-
settings_obj, *, compact=False, show_secrets, **pydantic_export_options
70+
settings_obj,
71+
*,
72+
compact=False,
73+
json_serializer,
74+
show_secrets,
75+
**pydantic_export_options,
7176
):
7277
typer.echo(
73-
json.dumps(
78+
json_serializer(
7479
model_dump_with_secrets(
7580
settings_obj, show_secrets=show_secrets, **pydantic_export_options
7681
),
@@ -80,7 +85,9 @@ def print_as_json(
8085

8186

8287
def create_settings_command(
83-
settings_cls: type[BaseCustomSettings], logger: logging.Logger | None = None
88+
settings_cls: type[BaseCustomSettings],
89+
logger: logging.Logger | None = None,
90+
json_serializer=json.dumps,
8491
) -> Callable:
8592
"""Creates typer command function for settings"""
8693

@@ -145,6 +152,7 @@ def settings(
145152
settings_obj,
146153
compact=compact,
147154
show_secrets=show_secrets,
155+
json_serializer=json_serializer,
148156
**pydantic_export_options,
149157
)
150158
else:

packages/settings-library/tests/test_utils_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,9 @@ class FakeSettings(BaseCustomSettings):
434434
assert "secret" not in captured.out
435435
assert "Some info" not in captured.out
436436

437-
print_as_json(settings_obj, compact=True, show_secrets=False)
437+
print_as_json(
438+
settings_obj, compact=True, show_secrets=False, json_serializer=json.dumps
439+
)
438440
captured = capsys.readouterr()
439441
assert "secret" not in captured.out
440442
assert "**" in captured.out

0 commit comments

Comments
 (0)