RTE: module 'qttools' has no attribute 'initate_translator' (encFS when prompting the user for a password)
aryoda opened this issue · 7 comments
Reported via PR #1552 (THX to @asciiprod)
Symptoms
When using encFs
(mode "local encryption") in a BiT config
and the password is not stored in a keyring (nor cached)
and the profile has an active schedule (= uses cron
)
instead of opening a message box to ask for the encFS
password this RTE is shown:
File "<inst folder>/backintime/qt/messagebox.py", line 26, in askPasswordDialog
translator = qttools.initate_translator(language_code)
AttributeError: module 'qttools' has no attribute 'initate_translator'. Did you mean: 'initiate_translator'?
Impact
BiT cron
jobs for such encFS
profiles silently fail instead of asking the user for a password
Steps to reproduce
TODO Add steps to reproduce in BiT GUI
On the console (just to test if you are affected):
python -c "import messagebox; pw = messagebox.askPasswordDialog(None, 'Test', 'prompt', 'en', 10)"
Analysis
As the error says: There is a typo in the function name:
translator = qttools.initate_translator(language_code)
should be
translator = qttools.initiate_translator(language_code)
Introduced on Aug 9, 2023 with commit e52c324 ("feat: Language in config file (#1493)") into
Lines 23 to 27 in 92a2016
Affected release versions
Proposed fix
See PR #1552
Recommended dev process changes
GUI testing of all possible code paths (driven by user choices and configs) is nearly impossible (neither manually nor automated).
When preparing a new release a code linter or PyCharm's "Problems" tab should be used to find such problems.
TODOs
- Mention bug in release v1.4.0 and v1.4.1 (DONE)
- Merge PR to fix it (DONE)
- Add changelog entry to mention the fix (DONE)
- Add "check linter/PyCharm problems tab" in BiT release process documentation (DONE)
I have reduced the criticality level of the bug from HIGH to MEDIUM after looking deeper into the source code because
- it affects only
encfs
("local encryption") configs - and when the password GUI is (indirectly by starting a backup) opened from the command line (the BiT GUI must be installed)
> ./backintime --profile "encFS test" backup
Back In Time
Version: 1.4.2-dev
Back In Time comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; type `backintime --license' for details.
INFO: Lock
Traceback (most recent call last):
File "/home/<user>/dev/backintime/common/backintime.py", line 1190, in <module>
startApp()
File "/home/<user>/dev/backintime/common/backintime.py", line 523, in startApp
args.func(args)
File "/home/<user>/dev/backintime/common/backintime.py", line 764, in backup
ret = takeSnapshot(cfg, force)
File "/home/<user>/dev/backintime/common/backintime.py", line 97, in takeSnapshot
ret = snapshots.Snapshots(cfg).backup(force)
File "/home/<user>/dev/backintime/common/snapshots.py", line 738, in backup
hash_id = mount.Mount(cfg = self.config).mount()
File "/home/<user>/dev/backintime/common/mount.py", line 227, in mount
return backend.mount(check = check)
File "/home/<user>/dev/backintime/common/mount.py", line 526, in mount
self._mount()
File "/home/<user>/dev/backintime/common/encfstools.py", line 62, in _mount
self.password = self.config.password(self.parent, self.profile_id, self.mode)
File "/home/<user>/dev/backintime/common/config.py", line 811, in password
return self.pw.password(parent, profile_id, mode, pw_id, only_from_keyring)
File "/home/<user>/dev/backintime/common/password.py", line 197, in password
password = self.passwordFromUser(parent, profile_id, mode, pw_id)
File "/home/<user>/dev/backintime/common/password.py", line 267, in passwordFromUser
password = messagebox.askPasswordDialog(
File "/home/<user>/dev/backintime/qt/messagebox.py", line 26, in askPasswordDialog
translator = qttools.initate_translator(language_code)
AttributeError: module 'qttools' has no attribute 'initate_translator'. Did you mean: 'initiate_translator'?
This code as an example
import qttools
def askPasswordDialog(parent, title, prompt, language_code, timeout):
if parent is None:
translator = qttools.initate_translator(language_code)
# ^^ mssing "i"
I can not find a linter/checker who is able to detect that initate_translator()
typo. The reason seems to be that that none of them do look into the imported modules.
Any suggestions on that?
I read that some IDE's (e.g. PyCharm) are able to detect such problems. But we can not integrate them into our CI or unit tests.
My current IDE setup (Emacs plus some magic) is also not able to detect that.
The reason seems to be that that none of them do look into the imported modules.
That's why I started to use coveralls.io and created unittests which trigger every function at least once.
That's why I started to use coveralls.io and created unittests which trigger every function at least once.
I do agree that a 100% coverage (incl. GUI code) with real unit tests should be the preferred solution here. But it is a long way.
I can not find a linter/checker who is able to detect that
initate_translator()
typo. The reason seems to be that that none of them do look into the imported modules.
Standard pylint
can detect the missing function - as long as the file is in the qt
sub folder so that the qttools
file can be imported:
~/dev/backintime/qt (doc/ssh_setup) > python -m pylint playground.py
************* Module playground
playground.py:1:0: C0114: Missing module docstring (missing-module-docstring)
playground.py:3:0: C0103: Function name "askPasswordDialog" doesn't conform to snake_case naming style (invalid-name)
playground.py:3:0: C0116: Missing function or method docstring (missing-function-docstring)
playground.py:5:21: E1101: Module 'qttools' has no 'initate_translator' member; maybe 'initiate_translator'? (no-member)
playground.py:3:30: W0613: Unused argument 'title' (unused-argument)
playground.py:3:37: W0613: Unused argument 'prompt' (unused-argument)
playground.py:3:60: W0613: Unused argument 'timeout' (unused-argument)
playground.py:5:8: W0612: Unused variable 'translator' (unused-variable)
----------------------------------------------------------------------
Your code has been rated at -20.00/10 (previous run: -20.00/10, +0.00)
I read that some IDE's (e.g. PyCharm) are able to detect such problems.
PyCharm just uses pylint
(configured as "external tool") and does also detect the typo:
pylint
does support checking only specific rules. How about performing only critical checks via TravisCI and as make
target, eg. like this:
~/dev/backintime/qt (doc/ssh_setup) > python -m pylint --disable=all --enable=E1101 playground.py
************* Module playground
playground.py:5:21: E1101: Module 'qttools' has no 'initate_translator' member; maybe 'initiate_translator'? (no-member)
----------------------------------------------------------------------
Your code has been rated at -2.50/10 (previous run: -20.00/10, +17.50)