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

Error when creating CheckBox with border_side.stroke_align provided as Enum #4491

Closed
1 task done
InesaFitsner opened this issue Dec 4, 2024 · 0 comments · Fixed by #4526
Closed
1 task done

Error when creating CheckBox with border_side.stroke_align provided as Enum #4491

InesaFitsner opened this issue Dec 4, 2024 · 0 comments · Fixed by #4526
Assignees
Labels
bug Something isn't working
Milestone

Comments

@InesaFitsner
Copy link
Contributor

Duplicate Check

Describe the bug

It works when border_side.stroke_align is a number but returns error when it is Enum. Also, it works with Enum for Chip.

The error:

Unhandled error processing page session : Traceback (most recent call last):
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/app.py", line 247, in on_session_created
    await asyncio.get_running_loop().run_in_executor(
  File "/Users/inesa/.pyenv/versions/3.12.6/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/playground/border_side_test.py", line 35, in main
    page.add(checkbox)
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/page.py", line 740, in add
    r = self.__update(self)
        ^^^^^^^^^^^^^^^^^^^
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/page.py", line 798, in __update
    commands, added_controls, removed_controls = self.__prepare_update(*controls)
                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/page.py", line 814, in __prepare_update
    control.build_update_commands(
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 492, in build_update_commands
    innerCmds = ctrl._build_add_commands(
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 557, in _build_add_commands
    childCmd = control._build_add_commands(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 546, in _build_add_commands
    command = self._build_command(False)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 573, in _build_command
    self.before_update()
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/checkbox.py", line 184, in before_update
    self._set_attr_json("borderSide", self.__border_side, wrap_attr_dict=True)
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 190, in _set_attr_json
    nv = self._convert_attr_json(
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 198, in _convert_attr_json
    json.dumps(value, cls=EmbedJsonEncoder, separators=(",", ":"))
  File "/Users/inesa/.pyenv/versions/3.12.6/lib/python3.12/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/embed_json_encoder.py", line 59, in encode
    return super().encode(self._convert_enums(o))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/inesa/.pyenv/versions/3.12.6/lib/python3.12/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/inesa/.pyenv/versions/3.12.6/lib/python3.12/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/Users/inesa/projects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/embed_json_encoder.py", line 49, in default
    obj_as_dict = self._convert_enums(obj.__dict__)
                                      ^^^^^^^^^^^^
AttributeError: 'mappingproxy' object has no attribute '__dict__'. Did you mean: '__dir__'?

Code sample

Code
import flet as ft


def main(page: ft.Page):

    checkbox = ft.Checkbox(
        label="Checkbox label",
        value=True,
        label_position=ft.LabelPosition.LEFT,
        label_style=ft.TextStyle(size=20),
        tristate=True,
        autofocus=True,
        fill_color={
            ft.ControlState.HOVERED: ft.Colors.GREEN,
            ft.ControlState.FOCUSED: ft.Colors.RED,
            ft.ControlState.DEFAULT: ft.Colors.BLACK,
        },
        overlay_color={
            ft.ControlState.HOVERED: ft.Colors.GREEN,
            ft.ControlState.FOCUSED: ft.Colors.RED,
            ft.ControlState.DEFAULT: ft.Colors.BLACK,
        },
        check_color=ft.Colors.GREEN_800,
        active_color=ft.Colors.GREEN_200,
        hover_color=ft.Colors.AMBER_300,
        focus_color=ft.Colors.RED_200,
        semantics_label="semantics label",
        shape=ft.RoundedRectangleBorder(10),
        splash_radius=5,
        border_side=ft.BorderSide(
            width=5, color=ft.Colors.RED, stroke_align=ft.BorderSideStrokeAlign.CENTER
        ),
    )

    page.add(checkbox)


ft.app(main)

To reproduce

  1. Run the repro code -> see the error in output

Expected behavior

No response

Screenshots / Videos

Captures

[Upload media here]

Operating System

macOS

Operating system details

macOS

Flet version

0.25.1

Regression

No, it isn't

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

@ndonkoHenri ndonkoHenri self-assigned this Dec 9, 2024
@ndonkoHenri ndonkoHenri added the bug Something isn't working label Dec 9, 2024
@ndonkoHenri ndonkoHenri added this to the Flet v0.25.2 milestone Dec 9, 2024
@ndonkoHenri ndonkoHenri moved this from 🆕 New to 👀 In review in Flet Development Dec 9, 2024
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Flet Development Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants