This forum has been archived. All content is frozen. Please use KDE Discuss instead.

5.23.5 DBUS-notification updates stop working

Tags: None
(comma "," separated)
User avatar
mchnz
Registered Member
Posts
18
Karma
0
I'm having some issues with notifications. I've got an application that updates DBUS notifications. At the start of a session notification updates work just fine. At some point in the session new notifications stop behaving as expected, the new notification remain visible, but it does not update. Furthermore, if I setup a callback for notification-close, the ID passed by the close event is different than ID returned when the notification was raised. Here is a typical sequence I see when debugging my application:

Code: Select all
DEBUG: notification_id  242 replace_id 0
DEBUG: notification_id  242 replace_id 242
...
DEBUG: notification_id  242 replace_id 242
DEBUG: notification_id  242 replace_id 242
DEBUG: notification_closed_handler (dbus.UInt32(302), dbus.UInt32(2))


In the above sequence I see the notification raised, I don't see any of the updates, and when I close the notification, I get passed a different notification ID for the close.

Once the error begins to happen even a simple tests, such as the following, fail to update a notification:
Code: Select all
import time

import dbus
from _dbus_glib_bindings import DBusGMainLoop

def main():
    notify_interface = dbus.Interface(
        object=dbus.SessionBus(mainloop=DBusGMainLoop(set_as_default=True)).get_object(
            "org.freedesktop.Notifications",
            "/org/freedesktop/Notifications"),
        dbus_interface="org.freedesktop.Notifications")

    message_id = notify_interface.Notify('test',
                                         0,
                                         'dialog-error',
                                         'my title'.encode('UTF-8'),
                                         'my message'.encode('UTF-8'),
                                         [],
                                         [],
                                         0)
    print("notification_id ", message_id)
    time.sleep(2)
    message_id = notify_interface.Notify('test',
                                         message_id,
                                         'dialog-error',
                                         'my title'.encode('UTF-8'),
                                         'my message updated'.encode('UTF-8'),
                                         [],
                                         [],
                                         0)
    print("notification_id ", message_id)
    time.sleep(2)

if __name__ == "__main__":
    main()


Just in case it was something to do with Python3 dbus, I also tried a test shell script:
Code: Select all
#!/bin/bash
# bash -x test-notify <start-notification-id> <num-updates> [<action-name>]
# For example:
#   bash -x test-notify 0 3
#   bash -x test-notify 0 2 my_action

id=${1:-0}

num_updates=${2:-1}

if [ -n "$3" ]
then
    action="['$3','$3']"
else
    action="[]"
fi

result=$(gdbus call --session \
    --dest=org.freedesktop.Notifications \
    --object-path=/org/freedesktop/Notifications \
    --method=org.freedesktop.Notifications.Notify \
    "fooapp" $id "dialog-error" 'Hello world!' "Start a notification with id=$id" \
    "$action" '{}' 0)

id=$(echo "$result" | sed 's/[(]uint32 //;s/,[)]//')
echo "notify returned id=$id"

for i in $(seq 1 $num_updates)
do
    sleep 1

    result=$(gdbus call --session \
    --dest=org.freedesktop.Notifications \
    --object-path=/org/freedesktop/Notifications \
    --method=org.freedesktop.Notifications.Notify \
    "fooapp" $id "dialog-error" 'Hello world!' "Update $i id=$id to $(date)." \
    "$action" '{}' 0)

    id=$(echo "$result" | sed 's/[(]uint32 //;s/,[)]//')
    echo "update returned id=$id"

done

The script normally works fine, but after the notification system has gone off the rails, the updates do not show up. Interestingly when the notification system is misbehaving, I can get the above shell script to work by supplying a non-zero invented notification ID as its first argument, for example, in the following case I pass 1234
Code: Select all
bash -x ~/test-dbus-notifications.sh 1234 3

This works, but is kind of tacky, it depends on my guessing an unused ID, and the systemd-journal logs org.kde.plasma.notifications: Trying to replace notification with id 1234 which doesn't exist, creating a new one. This is an application bug!.

I would raise a bug, but I cannot determine how to force the notifications system into this error state. I thought it was more likely to trigger if notifications had updates and actions, but I'm not sure. Once it is in this state only a reboot/logout will fix it.

Testing would be easier if the notifications sub-system could be successfully reset/restarted without logging out. Is that possible?

Any suggestions for narrowing this down would be appreciated.

(The actual python/Qt application I'm working on is at https://github.com/digitaltrails/procno.)




Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]