Skip to content

correctly handle backend rx.Field default values#5833

Merged
adhami3310 merged 1 commit intomainfrom
correctly-handle-backend-rx.Field-default-values
Sep 29, 2025
Merged

correctly handle backend rx.Field default values#5833
adhami3310 merged 1 commit intomainfrom
correctly-handle-backend-rx.Field-default-values

Conversation

@adhami3310
Copy link
Member

fixes #5829

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 29, 2025

CodSpeed Performance Report

Merging #5833 will not alter performance

Comparing correctly-handle-backend-rx.Field-default-values (2fe887a) with main (e2105fe)

Summary

✅ 8 untouched

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Summary

Fixed a bug where backend-only variables defined with rx.Field were storing the Field object itself instead of the actual default value, preventing method calls like .append() on mutable default values.

  • Modified backend variable processing to extract default values from Field objects using value.default_value()
  • Applied fix in both class initialization (new_backend_vars) and the _get_var_default method
  • Ensures backend variables with Field definitions behave consistently with regular state variables

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is targeted, addresses a specific bug with a clear root cause, uses existing APIs correctly, and maintains backward compatibility
  • No files require special attention

Important Files Changed

File Analysis

Filename        Score        Overview
reflex/state.py 5/5 Fixed backend Field handling to extract default values instead of storing Field objects

Sequence Diagram

sequenceDiagram
    participant User as User Code
    participant State as BaseState
    participant Field as rx.Field
    participant BackendVars as backend_vars

    Note over User: _list_1: rx.Field[list[int]] = rx.field([1])
    
    User->>State: Class initialization
    State->>State: Process backend variables
    
    alt Before Fix
        State->>BackendVars: Store Field object directly
        Note over BackendVars: backend_vars['_list_1'] = Field object
        User->>BackendVars: self._list_1.append(1)
        BackendVars-->>User: AttributeError: Field has no append()
    else After Fix
        State->>Field: Check if isinstance(value, Field)
        Field->>State: True
        State->>Field: value.default_value()
        Field->>State: [1] (actual list)
        State->>BackendVars: Store actual default value
        Note over BackendVars: backend_vars['_list_1'] = [1]
        User->>BackendVars: self._list_1.append(1)
        BackendVars-->>User: Success: [1, 1]
    end
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@adhami3310 adhami3310 merged commit 0225b96 into main Sep 29, 2025
41 checks passed
@adhami3310 adhami3310 deleted the correctly-handle-backend-rx.Field-default-values branch September 29, 2025 18:53
@benedikt-bartscher
Copy link
Contributor

Closes #5629 ?

@adhami3310
Copy link
Member Author

Closes #5629 ?

yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend-only vars no longer mutable

3 participants