Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTE: module 'qttools' has no attribute 'initate_translator' (encFS when prompting the user for a password) #1553

Closed
aryoda opened this issue Oct 20, 2023 · 7 comments
Assignees
Labels
Bug EncFS using the EncFS file system Medium
Milestone

Comments

@aryoda
Copy link
Contributor

aryoda commented Oct 20, 2023

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

def askPasswordDialog(parent, title, prompt, language_code, timeout):
if parent is None:
app = qttools.createQApplication()
translator = qttools.initate_translator(language_code)
app.installTranslator(translator)

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.

@aryoda aryoda added High Bug EncFS using the EncFS file system labels Oct 20, 2023
@aryoda aryoda self-assigned this Oct 20, 2023
@aryoda
Copy link
Contributor Author

aryoda commented Oct 20, 2023

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)

@aryoda aryoda added Medium and removed High labels Oct 21, 2023
@aryoda
Copy link
Contributor Author

aryoda commented Oct 21, 2023

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'?

@aryoda aryoda closed this as completed in 8f31987 Oct 21, 2023
aryoda added a commit that referenced this issue Oct 21, 2023
@emtiu emtiu added this to the 1.4.2 (upcoming release) milestone Oct 22, 2023
@buhtz
Copy link
Member

buhtz commented Nov 6, 2023

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.

@Germar
Copy link
Member

Germar commented Nov 6, 2023

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.

@buhtz
Copy link
Member

buhtz commented Nov 6, 2023

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.

@aryoda
Copy link
Contributor Author

aryoda commented Nov 7, 2023

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:

image

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)

@buhtz
Copy link
Member

buhtz commented Nov 7, 2023

Further discussion in #1558

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug EncFS using the EncFS file system Medium
Projects
None yet
Development

No branches or pull requests

4 participants