irmen / Pyro5

Pyro 5 - Python remote objects
https://pyro5.readthedocs.io
MIT License
303 stars 36 forks source link

Improve registration robustness for instances of registered classes #85

Open mawildoer opened 7 months ago

mawildoer commented 7 months ago

I am trying to remotely control a very OO interface by leveraging Pyro5's autoproxying features

I implemented a version of this workaround in a util function in the module I was working on and thought the same case might cause issues for others too.

The issue arrises when you do something like:

from kigadgets.util import register_return
from Pyro5.api import expose, Daemon

daemon = Daemon()

@expose
class Returned(object):
    pass  # not important

daemon.register(Returned)

@expose
class Dummy(object):
    @property
    def thingo(self) -> Returned:
        result = Returned()
        self._pyroDaemon.register(result)
        return result

dummy = Dummy()
daemon.register(dummy)
dummy.thingo
irmen commented 7 months ago

what exactly was the issue you encountered initially?

mawildoer commented 7 months ago

If you try register an instance of a class that's already registered, it'll raise a DaemonError.

Seems to be because the _pyroId is inherited from the parent class, and is therefore already present, even if the instance itself is unregistered.

I don't want to blindly use force=True in this case because I'm connecting up a third-party lib that is going to return other instances of exposed classes.

irmen commented 7 months ago

Could you perhaps add a unit test for this change as well? I think test_daemon.py could be the right place for it.