Skip to content

Commit e272d08

Browse files
authored
Merge pull request fastapi#34 from fastapilabs/09-16-_store_app_id_instead_of_slug
♻️ Store app id instead of slug
2 parents 98c5e68 + 26f71f3 commit e272d08

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/fastapi_cli/commands/deploy.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ def _configure_app(
229229

230230
progress.log(f"App created successfully! App slug: {app_data.slug}")
231231

232-
return write_app_config(path_to_deploy, slug=app_data.slug), app_data
232+
app_config = AppConfig(app_id=app_data.id)
233+
234+
write_app_config(path_to_deploy, app_config)
235+
236+
return app_config, app_data
233237

234238

235239
def _wait_for_deployment(
@@ -318,11 +322,11 @@ def deploy(
318322
toolkit, path_to_deploy=path_to_deploy
319323
)
320324
else:
321-
toolkit.print(f"Deploying app [blue]{app_config.slug}[blue]...")
325+
toolkit.print("Deploying app...")
322326
toolkit.print_line()
323327

324328
with toolkit.progress("Checking app...", transient=True) as progress:
325-
app_data = _get_app(app_config.slug)
329+
app_data = _get_app(app_config.app_id)
326330

327331
if not app_data:
328332
progress.set_error(
@@ -353,7 +357,7 @@ def deploy(
353357

354358
check_deployment_url = (
355359
settings.base_frontend_url
356-
+ f"/apps/{app_config.slug}/deployments/{deployment.id}"
360+
+ f"/apps/{app_data.slug}/deployments/{deployment.id}"
357361
)
358362

359363
if not skip_wait:

src/fastapi_cli/utils/apps.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class AppConfig(BaseModel):
8-
slug: str
8+
app_id: str
99

1010

1111
def get_app_config(path_to_deploy: Path) -> Optional[AppConfig]:
@@ -17,15 +17,11 @@ def get_app_config(path_to_deploy: Path) -> Optional[AppConfig]:
1717
return AppConfig.model_validate_json(config_path.read_text(encoding="utf-8"))
1818

1919

20-
def write_app_config(path_to_deploy: Path, slug: str) -> AppConfig:
20+
def write_app_config(path_to_deploy: Path, app_config: AppConfig) -> None:
2121
config_path = path_to_deploy / ".fastapi/cloud.json"
2222
config_path.parent.mkdir(parents=True, exist_ok=True)
2323

24-
app_config = AppConfig(slug=slug)
25-
2624
config_path.write_text(
2725
app_config.model_dump_json(),
2826
encoding="utf-8",
2927
)
30-
31-
return app_config

tests/test_cli_deploy.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ def test_exists_successfully_when_deployment_is_done_when_app_is_configured(
346346
config_path = tmp_path / ".fastapi" / "cloud.json"
347347

348348
config_path.parent.mkdir(parents=True, exist_ok=True)
349-
config_path.write_text('{"slug": "demo"}')
349+
config_path.write_text('{"app_id": "1234"}')
350350

351-
respx_mock.get("/apps/demo").mock(
351+
respx_mock.get("/apps/1234").mock(
352352
return_value=Response(200, json={"slug": "demo", "id": "1234"})
353353
)
354354

@@ -413,9 +413,9 @@ def test_shows_error_when_app_does_not_exist(
413413
config_path = tmp_path / ".fastapi" / "cloud.json"
414414

415415
config_path.parent.mkdir(parents=True, exist_ok=True)
416-
config_path.write_text('{"slug": "demo"}')
416+
config_path.write_text('{"app_id": "some-random-id"}')
417417

418-
respx_mock.get("/apps/demo").mock(return_value=Response(404))
418+
respx_mock.get("/apps/some-random-id").mock(return_value=Response(404))
419419

420420
with changing_dir(tmp_path):
421421
result = runner.invoke(app, ["deploy"])

0 commit comments

Comments
 (0)