Description
The framework's auto-unwrapping logic in templates (which allows using reactive variables without .value) is too aggressive. When a reactive container (like WireDict or WireNamespace) is used in a nested path like {user.profile.name}, the compiler transforms it into unwrap_wire(self.user).profile.name. However, unwrap_wire often returns a raw Python object (like a dict), which does not support dot-access, leading to an AttributeError.
Reproduction Steps
- Create a page with a nested reactive object:
user = wire(profile={"name": "Admin"}).
- In the template, try to access
user.profile.name: <p>{user.profile.name}</p>.
- The page will crash with
AttributeError: 'dict' object has no attribute 'profile' because user was unwrapped to a dict.
Expected Behavior
The compiler should recognize when a dot-access path is being used on a reactive container and defer unwrapping or handle it in a way that preserves dot-access (e.g., by not unwrapping recursive layers until the leaf property is reached, or by ensuring the unwrapped object also supports dot-access).
Proposed Fix
Modify src/pywire/compiler/codegen/template.py to refine visit_Attribute and visit_Name logic. It should detect when a variable is a complex reactive object and avoid premature unwrapping that loses dot-access capabilities.
Description
The framework's auto-unwrapping logic in templates (which allows using reactive variables without
.value) is too aggressive. When a reactive container (likeWireDictorWireNamespace) is used in a nested path like{user.profile.name}, the compiler transforms it intounwrap_wire(self.user).profile.name. However,unwrap_wireoften returns a raw Python object (like adict), which does not support dot-access, leading to anAttributeError.Reproduction Steps
user = wire(profile={"name": "Admin"}).user.profile.name:<p>{user.profile.name}</p>.AttributeError: 'dict' object has no attribute 'profile'becauseuserwas unwrapped to a dict.Expected Behavior
The compiler should recognize when a dot-access path is being used on a reactive container and defer unwrapping or handle it in a way that preserves dot-access (e.g., by not unwrapping recursive layers until the leaf property is reached, or by ensuring the unwrapped object also supports dot-access).
Proposed Fix
Modify
src/pywire/compiler/codegen/template.pyto refinevisit_Attributeandvisit_Namelogic. It should detect when a variable is a complex reactive object and avoid premature unwrapping that loses dot-access capabilities.