Skip to content

Conversation

@masenf
Copy link
Collaborator

@masenf masenf commented Dec 15, 2025

When the method's __self__ is a class, then we just return the classmethod value directly with no rebinding.

When the method's `__self__` is a class, then we just return the classmethod
value directly with no rebinding.
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 15, 2025

CodSpeed Performance Report

Merging #6045 will improve performances by 4.67%

Comparing masenf/mutable-proxy-classmethods (4f2c52e) with main (7826d0b)

Summary

⚡ 2 improvements
✅ 6 untouched

Benchmarks breakdown

Benchmark BASE HEAD Change
test_get_all_imports[_complicated_page] 23.8 ms 22.7 ms +4.67%
test_get_all_imports[_stateful_page] 3.2 ms 3.1 ms +3.65%

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 15, 2025

Greptile Overview

Greptile Summary

Fixed a bug in MutableProxy.__getattribute__ where classmethods were incorrectly being rebound with the proxy instance. The fix adds a check to detect when value.__self__ is a class (indicating a classmethod) and skips rebinding in that case. The test case verifies that calling a classmethod on a proxied dataclass doesn't incorrectly mark the state as dirty.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is a targeted bug fix with proper test coverage that correctly handles the classmethod edge case without affecting existing functionality
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
reflex/istate/proxy.py 5/5 Fixed classmethod rebinding issue by checking if __self__ is a class before rebinding
tests/units/test_state.py 5/5 Added test case for classmethod on proxied dataclass to verify it doesn't mark state dirty

Sequence Diagram

sequenceDiagram
    participant Test as test_mutable_models
    participant State as PydanticState
    participant Proxy as MutableProxy (state.dc)
    participant ModelDC as ModelDC Class
    
    Test->>Proxy: state.dc.from_dict({"foo": "from_dict", "ls": []})
    Note over Proxy: __getattribute__("from_dict")
    Proxy->>Proxy: Check if callable
    Proxy->>Proxy: Get value.__func__ and value.__self__
    Proxy->>Proxy: inspect.isclass(value.__self__)?
    Note over Proxy: value.__self__ is ModelDC class<br/>(classmethod detected)
    Proxy->>Proxy: Skip rebinding, return classmethod as-is
    Proxy->>ModelDC: Call from_dict({"foo": "from_dict", "ls": []})
    ModelDC->>ModelDC: Create new instance
    ModelDC-->>Proxy: Return ModelDC(foo="from_dict", ls=[])
    Proxy-->>Test: Return new instance
    Note over State: dirty_vars remains empty<br/>(classmethod doesn't mutate state)
Loading

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.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@adhami3310 adhami3310 merged commit 0ef2a87 into main Dec 15, 2025
58 of 59 checks passed
@adhami3310 adhami3310 deleted the masenf/mutable-proxy-classmethods branch December 15, 2025 20:39
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.

3 participants