jedie / cli-base-utilities

Helpers to build a CLI program
0 stars 0 forks source link

UserSettings with bool crashes when bool value is changed #50

Closed kosl closed 2 months ago

kosl commented 3 months ago

If UserSettings contains bool value and when changed to non-default then (de)serialisation fails with AttributeError: 'bool' object has no attribute 'unwrap'.

kosl commented 3 months ago
 File "cli_base/toml_settings/api.py", line 81, in get_user_settings
    document_changed = toml2dataclass(document=user_settings_doc, instance=self.settings_dataclass)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cli_base/toml_settings/deserialize.py", line 36, in toml2dataclass
    changed = toml2dataclass(document=sub_doc, instance=field_value, _changed=_changed)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cli_base/toml_settings/deserialize.py", line 70, in toml2dataclass
    elif not isinstance(field_value, type(doc_value.unwrap())):                
                                          ^^^^^^^^^^^^^^^^                                                                                                    
AttributeError: 'bool' object has no attribute 'unwrap'                                                                                                       
jedie commented 2 months ago

fixed by https://github.com/jedie/cli-base-utilities/pull/52

jedie commented 2 months ago

released in: https://pypi.org/project/cli-base-utilities/0.10.2/

kosl commented 2 months ago

Still toggling the value is inert.

jedie commented 2 months ago

Hm. Sad. We have to fix that. Currently i have no project that used a boolean value ;)

kosl commented 2 months ago

Well, bool is not a showstopper as it can be mimicked by int 0/1.

jedie commented 2 months ago

It's now fixed in 0.10.3: https://pypi.org/project/cli-base-utilities/0.10.3/