#1034878 meld gives python traceback if run as root

Package:
meld
Source:
meld
Submitter:
Wookey
Date:
2024-05-09 17:36:05 UTC
Severity:
normal
Tags:
#1034878#5
Date:
2023-04-26 15:04:25 UTC
From:
To:
I change to root inorder to be able to access some files to diff and ran meld. I got the following traceback:
root@mongol:~# meld
Traceback (most recent call last):
  File "/usr/bin/meld", line 463, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/bin/meld", line 458, in main
    setup_settings()
  File "/usr/bin/meld", line 317, in setup_settings
    meld.settings.create_settings()
  File "/usr/lib/python3/dist-packages/meld/settings.py", line 124, in create_settings
    _meldsettings = MeldSettings()
                    ^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/meld/settings.py", line 39, in __init__
    self.on_setting_changed(settings, 'prefer-dark-theme')
  File "/usr/lib/python3/dist-packages/meld/settings.py", line 58, in on_setting_changed
    gtk_settings.props.gtk_application_prefer_dark_theme = prefer_dark
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'props'

~#meld boot0 boot1
(i.e supplying filenames) gave the same output.

meld runs fine when run as the desktop user
It should deal more elegantly with this situation.

#1034878#10
Date:
2024-05-04 12:35:11 UTC
From:
To:
Bug #1034878 <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1034878>  -
meld gives python traceback if run as root
<https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1034878>  is caused by
the call to Gtk.Settings.get_default() in settings.py at about line 56.



This code still exists in the head of the git repo.



As per the PyAPI manual at
https://lazka.github.io/pgi-docs/Gtk-3.0/classes/Settings.html#Gtk.Settings.
get_default . If Gtk is not initialised (which often happens when you sudo
root over a remote shell as you need to pass xauth) then the call to
Gtk.Settings.get_default() will fail and return None.  This is not handled.
The issue is that a couple lines down instead of referencing
Gtk.Setting.props it now looks for (None).props... and breaks as per the bug
report.  Something like following two/four lines are required, though that
is really only a partial fix, as this will eliminate the Python error as per
the bug, but meld will still die horribly this time with a Gtk error, rather
than exit gracefully while informing the user.
I don't know enough about Gtk or meld to fix that.




            gtk_settings = Gtk.Settings.get_default()

 >          # even if the user has settings in their profile

             prefer_dark = settings.get_boolean(key)

             gtk_settings.props.gtk_application_prefer_dark_theme =
prefer_dark

Cheers,

Jay (the-moog at github)

#1034878#15
Date:
2024-05-04 15:35:57 UTC
From:
To:
Control: forwarded -1 https://gitlab.gnome.org/GNOME/meld/-/issues/846
Control: severity -1 minor

In general, GNOME developers and the Debian GNOME team don't want you
running apps as root/sudo. We do expect some things to be broken if
you try it anyway. However, you can try raising this issue directly
with the upstream meld developers who may be willing to apply a fix
for the issue. I notice that someone already reported a similar issue
today but maybe you can add a comment with your additional research.

https://gitlab.gnome.org/GNOME/meld/-/issues/846

Thank you,
Jeremy Bícha