Skip to content

Commit 70f7b5b

Browse files
authored
🐛 Fix env list for secret environment variables (#147)
The API does not return a `value` field for secret environment variables. This caused a Pydantic validation error when listing env vars. Make the `value` field optional to handle this case.
1 parent 6367192 commit 70f7b5b

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/fastapi_cloud_cli/commands/env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from pathlib import Path
3-
from typing import Annotated, Any, Union
3+
from typing import Annotated, Any, Optional, Union
44

55
import typer
66
from pydantic import BaseModel
@@ -16,7 +16,7 @@
1616

1717
class EnvironmentVariable(BaseModel):
1818
name: str
19-
value: str
19+
value: Optional[str] = None
2020

2121

2222
class EnvironmentVariableResponse(BaseModel):

tests/test_env_list.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,32 @@ def test_shows_environment_variables_names(
8585
assert result.exit_code == 0
8686
assert "SECRET_KEY" in result.output
8787
assert "API_KEY" in result.output
88+
89+
90+
@pytest.mark.respx(base_url=settings.base_api_url)
91+
def test_shows_secret_environment_variables_without_value(
92+
logged_in_cli: None, respx_mock: respx.MockRouter, configured_app: ConfiguredApp
93+
) -> None:
94+
"""Test that secret env vars without a value field are handled correctly."""
95+
respx_mock.get(f"/apps/{configured_app.app_id}/environment-variables/").mock(
96+
return_value=Response(
97+
200,
98+
json={
99+
"data": [
100+
{
101+
"name": "SECRET_KEY",
102+
"is_secret": True,
103+
"created_at": "2026-01-13T19:01:07.408378Z",
104+
"updated_at": "2026-01-13T19:01:07.408389Z",
105+
"connected_resource": None,
106+
},
107+
]
108+
},
109+
)
110+
)
111+
112+
with changing_dir(configured_app.path):
113+
result = runner.invoke(app, ["env", "list"])
114+
115+
assert result.exit_code == 0
116+
assert "SECRET_KEY" in result.output

0 commit comments

Comments
 (0)