Bug 488765

Summary: Comic manager raises exception on null paths
Product: [Applications] krita Reporter: Elender <elenderg>
Component: GeneralAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: minor CC: rojasreinold
Priority: NOR    
Version First Reported In: 5.2.2   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Elender 2024-06-20 00:45:25 UTC
SUMMARY


STEPS TO REPRODUCE
1.  Open Krita
2.  Create a new document
3.  On the "comic management panel" Right click on "Add new page from template".
4.  Cancel the dialog

OBSERVED RESULT

An exception ocurred while running the script.

ValueError: no path specified

ValueError
Python 3.10.7: C:\Program Files\Krita (x64)\bin\krita.exe
Wed Jun 19 20:50:12 2024

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 C:\Program Files\Krita (x64)\share\krita\pykrita\comics_project_management_tools\comics_project_manager_docker.py in slot_add_new_page_from_template(self=<comics_project_management_tools.comics_project_manager_docker.comics_project_manager_docker object>)
  609     def slot_add_new_page_from_template(self):
  610         if "templateLocation" not in self.setupDictionary.keys():
  611             self.setupDictionary["templateLocation"] = os.path.relpath(QFileDialog.getExistingDirectory(caption=i18n("Where are the templates located?"), options=QFileDialog.ShowDirsOnly), self.projecturl)
  612 
  613         templateDir = os.path.join(self.projecturl, self.setupDictionary["templateLocation"])
self = <comics_project_management_tools.comics_project_manager_docker.comics_project_manager_docker object>
self.setupDictionary = {}
global os = <module 'os' from 'C:\\Program Files\\Krita (x64)\\python\\python310.zip\\os.pyc'>
os.path = <module 'ntpath' from 'C:\\Program Files\\Krita (x64)\\python\\python310.zip\\ntpath.pyc'>
os.path.relpath = <function relpath>
global QFileDialog = <class 'PyQt5.QtWidgets.QFileDialog'>
QFileDialog.getExistingDirectory = <built-in function getExistingDirectory>
caption undefined
builtini18n = <built-in function krita_i18n>
options undefined
QFileDialog.ShowDirsOnly = 1
self.projecturl = None

 C:\Program Files\Krita (x64)\ntpath.py in relpath(path='', start='.')

ValueError: no path specified
    __cause__ = None
    __class__ = <class 'ValueError'>
    __context__ = None
    __delattr__ = <method-wrapper '__delattr__' of ValueError object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of ValueError object>
    __doc__ = 'Inappropriate argument value (of correct type).'
    __eq__ = <method-wrapper '__eq__' of ValueError object>
    __format__ = <built-in method __format__ of ValueError object>
    __ge__ = <method-wrapper '__ge__' of ValueError object>
    __getattribute__ = <method-wrapper '__getattribute__' of ValueError object>
    __gt__ = <method-wrapper '__gt__' of ValueError object>
    __hash__ = <method-wrapper '__hash__' of ValueError object>
    __init__ = <method-wrapper '__init__' of ValueError object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of ValueError object>
    __lt__ = <method-wrapper '__lt__' of ValueError object>
    __ne__ = <method-wrapper '__ne__' of ValueError object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of ValueError object>
    __reduce_ex__ = <built-in method __reduce_ex__ of ValueError object>
    __repr__ = <method-wrapper '__repr__' of ValueError object>
    __setattr__ = <method-wrapper '__setattr__' of ValueError object>
    __setstate__ = <built-in method __setstate__ of ValueError object>
    __sizeof__ = <built-in method __sizeof__ of ValueError object>
    __str__ = <method-wrapper '__str__' of ValueError object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ('no path specified',)
    with_traceback = <built-in method with_traceback of ValueError object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "C:\Program Files\Krita (x64)\share\krita\pykrita\comics_project_management_tools\comics_project_manager_docker.py", line 611, in slot_add_new_page_from_template
    self.setupDictionary["templateLocation"] = os.path.relpath(QFileDialog.getExistingDirectory(caption=i18n("Where are the templates located?"), options=QFileDialog.ShowDirsOnly), self.projecturl)
  File "ntpath.py", line 735, in relpath
ValueError: no path specified


EXPECTED RESULT
The script just should ignore null paths


SOFTWARE/OS VERSIONS
Windows: Windows 11 21H2 Version
Krita: 5.2.2
Comment 1 Reinold Rojas 2024-11-18 23:56:36 UTC
I tried reproducing on Linux using the 5.2.2 but I wasn't able. Possibly this is Windows specific but I don't have a windows install to test.
Comment 2 Bug Janitor Service 2025-05-21 18:05:52 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/2402
Comment 3 Freya Lupen 2025-05-30 14:53:25 UTC
Git commit 54651080e1a070956aec269c0af39995a8630fa1 by Freya Lupen.
Committed on 30/05/2025 at 14:15.
Pushed by freyalupen into branch 'master'.

Add FileDialog to API and use it in plugins

FileDialog is a wrapper for KoFileDialog.
It respects Krita's 'Don't use native file dialogs' setting.
Also fix some plugins to properly ignore cancelled file dialogs.
Related: bug 499445

M  +2    -0    libs/libkis/CMakeLists.txt
A  +120  -0    libs/libkis/FileDialog.cpp     [License: LGPL(v2.0+)]
A  +171  -0    libs/libkis/FileDialog.h     [License: LGPL(v2.0+)]
M  +10   -0    libs/widgetutils/KoFileDialog.cpp
M  +6    -0    libs/widgetutils/KoFileDialog.h
A  +40   -0    plugins/extensions/pykrita/sip/krita/FileDialog.sip
M  +2    -0    plugins/extensions/pykrita/sip/krita/kritamod.sip
M  +20   -9    plugins/python/comics_project_management_tools/comics_project_manager_docker.py
M  +3    -3    plugins/python/comics_project_management_tools/comics_project_settings_dialog.py
M  +3    -3    plugins/python/comics_project_management_tools/comics_project_setup_wizard.py
M  +2    -1    plugins/python/comics_project_management_tools/comics_template_dialog.py
M  +9    -9    plugins/python/exportlayers/uiexportlayers.py
M  +5    -4    plugins/python/palette_docker/palette_exporter_gimppalette.py
M  +5    -5    plugins/python/palette_docker/palette_exporter_inkscapeSVG.py
M  +2    -4    plugins/python/photobash_images/photobash_images_docker.py
M  +7    -7    plugins/python/plugin_importer/plugin_importer_extension.py
M  +10   -9    plugins/python/scripter/ui_scripter/actions/openaction/openaction.py
M  +5    -6    plugins/python/scripter/ui_scripter/actions/saveaction/saveaction.py
M  +5    -7    plugins/python/scripter/ui_scripter/actions/saveasaction/saveasaction.py
M  +7    -8    plugins/python/tenscripts/uitenscripts.py
M  +13   -18   plugins/python/workflow_buttons/buttons_settings_dialog.py

https://invent.kde.org/graphics/krita/-/commit/54651080e1a070956aec269c0af39995a8630fa1