crash when encountering a broken reference
Hi, recently I played around a bit in my database and triggered this strange error:
Process DmenuRunner-2:
Traceback (most recent call last):
File "/usr/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
self.run()
File "/home/olaf/.local/python-venv/lib/python3.11/site-packages/keepmenu/keepmenu.py", line 333, in run
self.dmenu_run(self.server.totp_flag.is_set())
File "/home/olaf/.local/python-venv/lib/python3.11/site-packages/keepmenu/keepmenu.py", line 400, in dmenu_run
sel = view_all_entries(list(options), filtered_entries, self.database.dbase)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/olaf/.local/python-venv/lib/python3.11/site-packages/keepmenu/view.py", line 28, in view_all_entries
i.deref('username'),
^^^^^^^^^^^^^^^^^^^
File "/home/olaf/.local/python-venv/lib/python3.11/site-packages/pykeepass/entry.py", line 137, in deref
return self._kp.deref(getattr(self, attribute))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/olaf/.local/python-venv/lib/python3.11/site-packages/pykeepass/pykeepass.py", line 681, in deref
value = value.replace(ref, getattr(ref_entry, wanted_field))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'username'
(the line numbers are a bit off due to my debugging attempts)
I figured out, this occurs when there is a broken reference to another entry. Something like {REF:U@I:XXXXXXXXXXXXXXXX} in the user field where theXXXXXXXXXXXXXXXX is an invalid reference ID. I could not find a way to filter this somehow elegant so I hope you can fix it with this information. I think this is a bug in pykeepass and will report it there as well.
It seems like when your fix gets merged that the existing code i.deref('title') or "") should handle the issue. I may have to add the or "" to other deref calls.
That being said, I'll have to look further if there's a clean way to handle that error for older versions of pykeepass. Thanks for the report!