Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rx.cached_var does not find dependencies inside a list comprehension #1709

Closed
masenf opened this issue Aug 29, 2023 · 1 comment · Fixed by #1728
Closed

rx.cached_var does not find dependencies inside a list comprehension #1709

masenf opened this issue Aug 29, 2023 · 1 comment · Fixed by #1728

Comments

@masenf
Copy link
Collaborator

masenf commented Aug 29, 2023

Describe the bug
Using a cached var with a list comprehension does not get updated when the dependent vars change because ComputedVar.deps does not correctly identify dependencies inside a list comprehension.

To Reproduce

class State(rx.State):
    _selected_images: set[str] = set()

    def toggle_image(self, image: str):
        if image in self._selected_images:
            self._selected_images.remove(image)
        else:
            self._selected_images.add(image)

    @rx.cached_var
    def image_infos(self) -> list[ImageInfo]:
        breakpoint()
        return [
            ImageInfo(image=image, selected=image in self._selected_images)
            for image in IMAGES
        ]

👆 image_infos never gets updated 😢

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 a pull request may close this issue.

1 participant