fix(hosting-cli): make ScaleParams.as_json() side-effect free#6415
fix(hosting-cli): make ScaleParams.as_json() side-effect free#6415masenf merged 1 commit intoreflex-dev:mainfrom
Conversation
Greptile SummaryThis PR fixes a side-effect in Confidence Score: 5/5Safe to merge — minimal, targeted fix with a direct regression test and no logic changes beyond removing the mutation. The change is a one-line, obviously correct substitution of a local variable for a mutating assignment. The regression test directly exercises both properties (immutability of the field, idempotency of output). No other code paths are affected. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant ScaleParams
Note over Caller,ScaleParams: Before fix (mutating)
Caller->>ScaleParams: as_json() [type=None]
ScaleParams->>ScaleParams: self.type = ScaleType.REGION
ScaleParams-->>Caller: {"type": "region", ...}
Caller->>ScaleParams: as_json() [type=REGION now!]
ScaleParams-->>Caller: {"type": "region", ...}
Note over Caller,ScaleParams: After fix (pure)
Caller->>ScaleParams: as_json() [type=None]
ScaleParams->>ScaleParams: effective_type = REGION (local only)
ScaleParams-->>Caller: {"type": "region", ...}
Caller->>ScaleParams: as_json() [type=None still]
ScaleParams->>ScaleParams: effective_type = REGION (local only)
ScaleParams-->>Caller: {"type": "region", ...}
Reviews (1): Last reviewed commit: "fix(hosting-cli): keep ScaleParams.as_js..." | Re-trigger Greptile |
All Submissions:
Type of change
Changes To Core Features:
Description
ScaleParams.as_json()was mutatingself.typewhen the type was unset:if self.type is None: self.type = ScaleType.REGIONThis made serialization stateful and introduced side effects for callers reusing the same
ScaleParamsobject.This patch makes serialization pure by using a local
effective_typevariable:effective_type = self.type or ScaleType.REGIONNo object fields are mutated during
as_json().Tests
Added regression test:
test_scale_params_as_json_is_pure_when_type_is_unspecifiedThe test verifies:
as_json()calls are idempotentscale_params.typeremainsNoneafter serializationValidation
uv run ruff check packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py tests/units/reflex_cli/utils/test_hosting.pyuv run pytest tests/units/reflex_cli/utils/test_hosting.py -quv run pytest tests/units/reflex_cli/v2/test_apps.py -k scale -qFollow-up to #6369