mnemosyne.script: crash on relative data_path

Bug #1723670 reported by Julian Mehne
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
The Mnemosyne Project
Fix Committed
Undecided
Unassigned

Bug Description

Using a relative data_path with the script module crashes mnemosyne on the pbienst and mnemosyne-proj branches (with the Mnemosyne(None) fix applied). In the example below, the path does not exist. Using an existing path leads to a different error, but I think it has the same cause:

from mnemosyne.script import Mnemosyne

m = Mnemosyne('foobar')

Error message:

Previous drive letter no longer available.
If you are using a USB key, refer to the instructions on the website so as not to be affected by drive letter changes.
An unexpected error has occurred.
Please forward the following info to the developers:

Traceback (innermost last):
  File "./test.py", line 11, in <module>
    m = Mnemosyne('foobar')
  File "/home/kelvin/tmp/mnemosyne-pbienst/mnemosyne/mnemosyne/script/__init__.py", line 45, in __init__
    self.initialise(data_dir)
  File "/home/kelvin/tmp/mnemosyne-pbienst/mnemosyne/mnemosyne/libmnemosyne/__init__.py", line 220, in initialise
    self.load_database(filename)
  File "/home/kelvin/tmp/mnemosyne-pbienst/mnemosyne/mnemosyne/libmnemosyne/__init__.py", line 359, in load_database
    self.controller().show_open_file_dialog()
  File "/home/kelvin/tmp/mnemosyne-pbienst/mnemosyne/mnemosyne/libmnemosyne/controllers/default_controller.py", line 615, in show_open_file_dialog
    self.flush_sync_server()
  File "/home/kelvin/tmp/mnemosyne-pbienst/mnemosyne/mnemosyne/libmnemosyne/component.py", line 154, in flush_sync_server
    review_widget.stop_media()
 TypeError: stop_media() missing 1 required positional argument: 'self'
An unexpected error has occurred.

Some observations:

In mnemosyne/libmnemosyne/__init__.py:
path = expand_path(filename, self.config().data_dir)
-> path = expand_path('default.db', 'foobar')
returns path: 'foobar/default.db'

In mnemosyne/libmnemosyne/databases/SQLite.py
self._path = expand_path(path, self.config().data_dir)
-> self._path = expand_path('foobar/default.db', 'foobar')
returns _path: 'foobar/foobar/default.db'
This is probably wrong.

- Calling "mnemosyne/pyqt_ui/mnemosyne -d foobar" works fine, because "mnemosyne/pyqt_ui/mnemosyne" converts every path to an absolute path, before creating the Mnemosyne class.
- This papers over the crash, but the real fix would be somewhere else, I guess:
=== modified file 'mnemosyne/mnemosyne/script/__init__.py'
--- mnemosyne/mnemosyne/script/__init__.py 2017-10-09 11:42:41 +0000
+++ mnemosyne/mnemosyne/script/__init__.py 2017-10-14 22:08:21 +0000
@@ -2,6 +2,8 @@
 # script <email address hidden>
 #

+import os.path
+
 from mnemosyne.libmnemosyne import Mnemosyne as MnemosyneParent
 from mnemosyne.libmnemosyne.ui_components.main_widget import MainWidget
 from mnemosyne.libmnemosyne.ui_components.review_widget import ReviewWidget
@@ -41,4 +43,8 @@
             ("mnemosyne.script", "ScriptReviewWidget"))
         self.gui_for_component["ScheduledForgottenNew"] = \
             [("mnemosyne.script", "ScriptReviewWidget")]
+
+ if data_dir is not None:
+ data_dir = os.path.abspath(data_dir)
+
         self.initialise(data_dir)

Revision history for this message
Peter Bienstman (peter-bienstman) wrote :

committed in pbienst, thanks!

Changed in mnemosyne-proj:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.