diff --git a/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py b/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py index 010aa1b2823..30a0cd65d75 100644 --- a/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py +++ b/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py @@ -216,16 +216,15 @@ def as_json(self) -> dict[str, Any]: dict: The object as a dictionary. """ - if self.type is None: - self.type = ScaleType.REGION + effective_type = self.type or ScaleType.REGION return ( { - "type": str(self.type.value), + "type": str(effective_type.value), "size": self.vm_type, } - if self.type == ScaleType.SIZE + if effective_type == ScaleType.SIZE else { - "type": str(self.type.value), + "type": str(effective_type.value), "regions": { region["name"]: region["number_of_machines"] for region in self.regions diff --git a/tests/units/reflex_cli/utils/test_hosting.py b/tests/units/reflex_cli/utils/test_hosting.py index 312a12e3f09..89d05d96eeb 100644 --- a/tests/units/reflex_cli/utils/test_hosting.py +++ b/tests/units/reflex_cli/utils/test_hosting.py @@ -7,6 +7,8 @@ import pytest from pytest_mock import MockerFixture, MockFixture from reflex_cli.utils.hosting import ( + ScaleParams, + ScaleType, authenticated_token, delete_token_from_config, get_authenticated_client, @@ -164,3 +166,14 @@ def test_authenticate_with_env_token_in_non_interactive_mode(mocker: MockerFixtu assert result == mock_authenticated_client mock_get_auth_client.assert_called_once_with(None) + + +def test_scale_params_as_json_is_pure_when_type_is_unspecified(): + """ScaleParams.as_json should not mutate type when defaulting scale type.""" + scale_params = ScaleParams(vm_type="shared-1x") + + first = scale_params.as_json() + second = scale_params.as_json() + + assert scale_params.type is None + assert first == second == {"type": ScaleType.REGION.value, "regions": {}}