python-dbus-next icon indicating copy to clipboard operation
python-dbus-next copied to clipboard

Regression: no more introspection after "Improve unmarshall performance"

Open whot opened this issue 3 years ago • 0 comments

Commit "Improve unmarshall performance" (3282eed607cb7f9f64a3275d1f9155c0e65bd8f8) broke the introspection abilities. Trying to introspect now simply gives Remote peer disconnected.

Can be reproduced with the example high level service from the docs or this GLib based one:

#!/usr/bin/env python3
from dbus_next import BusType, Variant, PropertyAccess, DBusError
from dbus_next.glib import MessageBus
from dbus_next.service import ServiceInterface, method, dbus_property, signal
from gi.repository import GLib

import dbus_next


class Foo(ServiceInterface):
    def __init_(self, bus):
        bus.export("/com/example/sample0")

    @dbus_property(access=PropertyAccess.READ)
    def Integer(self) -> "i":  # type: ignore
        return 1


bus = MessageBus(bus_type=BusType.SESSION).connect_sync()
bus.request_name_sync("com.example.name", dbus_next.NameFlag.REPLACE_EXISTING)

try:
    mainloop = GLib.MainLoop()
    mainloop.run()
except KeyboardInterrupt:
    pass

To trigger the error, run this command:

$ gdbus introspect --session --dest com.example.name --object-path /com/example/sample0
Error: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Remote peer disconnected

In the GLib case it fails quietly with no error, the asyncio case returns this traceback:

/home/whot/tmp/2022-11-17-Thu/test_async.py:65: DeprecationWarning: There is no current event loop
  asyncio.get_event_loop().run_until_complete(main())
Traceback (most recent call last):
  File "/home/whot/tmp/2022-11-17-Thu/test_async.py", line 65, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "/usr/lib64/python3.11/asyncio/base_events.py", line 650, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/whot/tmp/2022-11-17-Thu/test_async.py", line 63, in main
    await bus.wait_for_disconnect()
  File "/home/whot/.local/lib/python3.11/site-packages/dbus_next/aio/message_bus.py", line 342, in wait_for_disconnect
    return await self._disconnect_future
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/whot/.local/lib/python3.11/site-packages/dbus_next/aio/message_bus.py", line 365, in _message_reader
    if self._unmarshaller.unmarshall():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/whot/.local/lib/python3.11/site-packages/dbus_next/_private/unmarshaller.py", line 297, in unmarshall
    self._read_header()
  File "/home/whot/.local/lib/python3.11/site-packages/dbus_next/_private/unmarshaller.py", line 247, in _read_header
    self.flag = MESSAGE_FLAG_MAP[buffer[2]]
                ~~~~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: 0

whot avatar Nov 17 '22 09:11 whot