Skip to content

Commit 3111358

Browse files
authored
šŸ›Fix printing ENVironment when object is a complex object such as dict or list (#8066)
1 parent 73cf774 commit 3111358

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ā€Žpackages/settings-library/src/settings_library/utils_cli.pyā€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def print_as_envfile(
2727
):
2828
exclude_unset = pydantic_export_options.get("exclude_unset", False)
2929

30-
for name, field in settings_obj.model_fields.items():
30+
for name, field in type(settings_obj).model_fields.items():
3131
auto_default_from_env = (
3232
field.json_schema_extra is not None
3333
and field.json_schema_extra.get("auto_default_from_env", False)
@@ -66,6 +66,9 @@ def print_as_envfile(
6666
typer.echo(f"# {field.description}")
6767
if isinstance(value, Enum):
6868
value = value.value
69+
elif isinstance(value, dict | list):
70+
# Serialize complex objects as JSON to ensure they can be parsed correctly
71+
value = json_dumps(value)
6972
typer.echo(f"{name}={value}")
7073

7174

0 commit comments

Comments
Ā (0)