flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
10.89k stars 419 forks source link

Issues with page.client_storage.set() function. #2864

Closed MaxXilon closed 6 months ago

MaxXilon commented 6 months ago

Description

Tried using the page.client_storage.set() to store a list but it returned ValueError: Circular Reference detected.

Code example to reproduce the issue:


def main(page):
  colors=['red','blue','green',]

  page.add(ft.Card(ft.Text('hi')))

  colors+=page.controls

  page.client_storage.set('color',colors)

  page.update()

  x=page.client_storage.get('color')

  print (x)

ft.app(main)

Describe the results you received:

Describe the results you expected:

The input list displayed at the console.

Additional information you deem important (e.g. issue happens only occasionally):

Flet version (pip show flet):

Name: flet
Version: 0.21.1
Summary: Flet for Python - easily build interactive multi-platform apps in Python
Home-page:
Author: Appveyor Systems Inc.
Author-email: hello@flet.dev
License: Apache-2.0
Location: /usr/local/lib/python3.10/dist-packages
Requires: cookiecutter, fastapi, flet-runtime, packaging, qrcode, uvicorn, watchdog
Required-by:

Give your requirements.txt file (don't pip freeze, instead give direct packages):

flet

Operating system:

Linux version: Distributor ID: Ubuntu Description: Ubuntu 22.04.4 LTS Release: 22.04 Codename: jammy

Android version: 8.1.0

burhansvural commented 6 months ago
import flet as ft

def main(page):
    colors=['red','blue','green']

    page.add(
        ft.Card(
            content=ft.Text('hi'))
        )

    colors+=page.controls

    print(colors)

    page.client_storage.set("color",str(colors))
    x=page.client_storage.get('color')

    print (x)

ft.app(main)
burhansvural commented 6 months ago

Also, an example of deleting a circular reference is available in the link below: https://stackoverflow.com/questions/44777369/remove-circular-references-in-dicts-lists-tuples

MaxXilon commented 6 months ago

Thanks 😊,