Skip to content

Conversation

@masenf
Copy link
Collaborator

@masenf masenf commented Dec 16, 2025

Just because some of the imports are not BaseState, doesn't mean we can't otherwise track dependencies for the computed var.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 16, 2025

CodSpeed Performance Report

Merging #6052 will not alter performance

Comparing masenf/dep-tracking-ignore-non-basestate (e4d5923) with main (bd1f7c6)

Summary

✅ 8 untouched

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 16, 2025

Greptile Overview

Greptile Summary

This PR adds graceful handling for non-BaseState classes during dependency tracking for computed vars. Previously, when tracked_locals contained a ModuleType object (from an import statement) instead of a BaseState subclass, the assert_base_state call would raise a VarValueError and halt dependency tracking entirely. The fix catches this exception and returns early, allowing dependency tracking to continue for other parts of the function.

  • Added try/except block around assert_base_state call in load_attr_or_method
  • Returns early when the target object is not a BaseState, allowing the tracker to continue processing other dependencies
  • Comment accurately describes the behavior: "If the target state is not a BaseState, we cannot track dependencies on it."

Confidence Score: 5/5

  • This is a safe, minimal fix that adds resilience to the dependency tracking system without changing expected behavior for valid use cases.
  • The change is small, focused, and handles an edge case gracefully. The fix follows the existing pattern in the code (early return when conditions aren't met) and doesn't modify any other behavior. The tracked_locals dictionary explicitly allows ModuleType values, so handling this case properly is the correct approach.
  • No files require special attention.

Important Files Changed

File Analysis

Filename Score Overview
reflex/vars/dep_tracking.py 5/5 Added graceful handling for non-BaseState objects in dependency tracking by catching VarValueError and returning early instead of crashing.

Sequence Diagram

sequenceDiagram
    participant DT as DependencyTracker
    participant LAM as load_attr_or_method
    participant ABS as assert_base_state
    
    DT->>LAM: Process LOAD_ATTR instruction
    LAM->>LAM: get_tracked_local(top_of_stack)
    LAM->>ABS: assert_base_state(target_obj)
    alt target_obj is BaseState
        ABS-->>LAM: return BaseState class
        LAM->>LAM: Continue tracking dependencies
    else target_obj is ModuleType (NEW)
        ABS-->>LAM: raise VarValueError
        LAM->>LAM: Catch exception, return early
        Note over LAM: Allows other dependencies to continue being tracked
    end
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.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@adhami3310 adhami3310 merged commit e9662f4 into main Dec 18, 2025
47 checks passed
@adhami3310 adhami3310 deleted the masenf/dep-tracking-ignore-non-basestate branch December 18, 2025 18:22
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