community icon indicating copy to clipboard operation
community copied to clipboard

Remove key errors in _widget_destructors when finishing app

Open LESSSE opened this issue 2 years ago • 7 comments

Maintainer merge checklist

  • [ ] Title is descriptive/clear for inclusion in release notes.
  • [ ] Applied a Component: xxx label.
  • [ ] Applied the api-deprecation or api-break label.
  • [ ] Applied the release-highlight label to be highlighted in release notes.
  • [ ] Added to the milestone version it was merged into.
  • [ ] Unittests are included in PR.
  • [ ] Properly documented, including versionadded, versionchanged as needed.

LESSSE avatar Sep 20 '21 13:09 LESSSE

Thanks for opening your first pull request here! 💖 Please check out our contributing guidelines.

welcome[bot] avatar Sep 20 '21 13:09 welcome[bot]

Was this part of the code raising an error and if so do you have the code to reproduce that error? My concern is that we may hide the actual issue instead of fixing it.

pythonic64 avatar Jan 25 '22 12:01 pythonic64

@pythonic64 it is also happening in my project too, i'll try to make a minimal runnable

p0lygun avatar Jan 25 '22 12:01 p0lygun

Error log sample:

Exception ignored in: functools.partial(<function _widget_destructor at 0x7ff2cf053a60>, 8952) Traceback (most recent call last): File "/home/lessse/Documents/facing/repos/deadpan_prototype/venv/lib/python3.8/site-packages/kivy/uix/widget.py", line 264, in _widget_destructor del _widget_destructors[uid] KeyError: 8952

This happens in a project using settings (SettingsWithSidebar). If during the app execution I open settings page, this error will spawn after closing the window. I suppose any small code using a settings page should show the error.

LESSSE avatar Feb 21 '22 16:02 LESSSE

ooof forgot about this, I had a minimal runnable just forgot to update this issue Minimal runnable

import json
from kivy.app import App
from kivy.config import ConfigParser
from kivy.lang import Builder
from kivy.uix.settings import SettingsWithSidebar, Settings

settings_json = [
    {
        "type":"numeric",
        "title":"test",
        "key":"test",
        "section":"test"
    }
]

kv = """
Button:
    text:'Open settings'
    on_release:app.open_settings()
"""


class Test(App):
    def build(self):
        self.settings_cls = SettingsWithSidebar
        self.config.read('test.ini')
        self.config.write()
        return Builder.load_string(kv)

    def build_settings(self, settings: Settings):
        settings.add_json_panel(
            "App Settings",
            self.config,
            data=json.dumps(settings_json)
        )

    def build_config(self, config: ConfigParser):
        config.read('test.ini')
        config.adddefaultsection('test')
        config.setdefaults('test', {'test': 0})
        config.write()


if __name__ == '__main__':
    Test().run()

The error occurs the the app is closed
~~and that too only when a value id changed~~ No happens every time

p0lygun avatar Feb 21 '22 17:02 p0lygun

Ok, this is actually a bug in kivy, where we seemingly overwrite the widget uid in label = SettingSidebarLabel(text=name, uid=uid, menu=self) so we end up creating multiple widgets with the same uid. We need to fix the underlying issue.

matham avatar Feb 21 '22 19:02 matham

We may want to consider disabling setting the uid as a property, except with a specific method so it's not accidentally set. That would have prevented the issue as the current code would raise an exception rather than quietly accepting a custom uid.

matham avatar Feb 22 '22 05:02 matham