qfieldsync
qfieldsync copied to clipboard
Fix runtime error after plugin update when `libqfieldsync` changed API
trafficstars
When we add a new class/method/API change in libqfieldsync and we use it within QFieldSync plugin, we get a runtime error, such as:
ImportError: cannot import name 'PackagingCanceledException' from 'libqfieldsync.offline_converter' (C:\Users\paul.bennett\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\qfieldsync\libqfieldsync.whl\libqfieldsync\offline_converter.py)
The reason is that libqfieldsync is loaded from a .whl file, which is cached by the Python runtime and we need to introduce this magic to force reload this.
The magic consists of two parts:
- ensure the new version .whl file has a different name 2) ensure we use
importlib.reloadto force reload from the new .whl
Tested on Windows 11 with QGIIS 3.34. Failed to reproduce on Ubuntu, but also did not try hard.
I wish I have time to do more fun stuff like this...
Fix #643 #646