datalad / datalad-gooey

A graphical user interface for DataLad (datalad.org)
https://docs.datalad.org/projects/gooey
Other
4 stars 6 forks source link

FSBrowserItem access broken after a "Refresh directory tree" #400

Closed mih closed 1 year ago

mih commented 1 year ago

I open any dir, I make changes to it outside the app, I manually refresh the browser view, I make any change in a visible dir outside the app:

INSPECT /home/mih/hacking/datalad/next/datalad_next/constraints
Traceback (most recent call last):
  File "/home/mih/hacking/datalad/gooey/datalad_gooey/fsbrowser.py", line 383, in _inspect_changed_dir
    print("-> ITEM", item)
  File "/home/mih/hacking/datalad/gooey/datalad_gooey/fsbrowser_item.py", line 28, in __str__
    return f'FSBrowserItem<{self.pathobj}>'
  File "/home/mih/hacking/datalad/gooey/datalad_gooey/fsbrowser_item.py", line 32, in pathobj
    p = self.data(0, FSBrowserItem.PathObjRole)
  File "/home/mih/hacking/datalad/gooey/datalad_gooey/fsbrowser_item.py", line 77, in data
    return super().data(column, role)
RuntimeError: Internal C++ object (FSBrowserItem) already deleted.

with this patch

diff --git a/datalad_gooey/fsbrowser.py b/datalad_gooey/fsbrowser.py
index 29f7293..e9dda52 100644
--- a/datalad_gooey/fsbrowser.py
+++ b/datalad_gooey/fsbrowser.py
@@ -356,6 +356,7 @@ class GooeyFilesystemBrowser(QObject):
             self._fswatcher.addPath(str(path / '.git' / 'refs' / 'heads'))

     def _inspect_changed_dir(self, path: str):
+        print("INSPECT", path)
         pathobj = Path(path)
         dir_exists = pathobj.exists()
         if not dir_exists:
@@ -379,6 +380,7 @@ class GooeyFilesystemBrowser(QObject):
         # to the changed directory
         try:
             item = self._get_item_from_path(pathobj)
+            print("-> ITEM", item)
         except ValueError:
             # the changed dir has no (longer) a matching entry in the
             # tree model. make sure to take it off the watch list

It seems to be reporting a browser item that belonged to the prevent tree content?

mih commented 1 year ago

Aha!

@lru_cache(maxsize=1000)
def _get_item_from_path(...)

The cache is not invalidated after the root item was replaced!