Skip to content

[Bug] Auto-unwrapping in templates breaks nested attribute access #21

@reecelikesramen

Description

@reecelikesramen

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

  1. Create a page with a nested reactive object: user = wire(profile={"name": "Admin"}).
  2. In the template, try to access user.profile.name: <p>{user.profile.name}</p>.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions