[Twisted-Python] Do Viewables absolutely have to be return'ed by Avatars?

Glyph glyph at twistedmatrix.com
Fri Nov 22 12:02:57 MST 2013


On Nov 20, 2013, at 3:54 PM, Daniel Sank <sank.daniel at gmail.com> wrote:

> From some experimentation I find that the only way to make a Viewable
> get a meaningful perspective argument when executing view_* methods is
> to make sure that the references to that Viewable are given to clients
> as return values from perspective_* methods called on a pb.Avatar.
> 
> In particular, if the Avatar gives a client a reference to a Viewable
> by passing it as an argument to a remote_* method on the client,
> subsequent invocations of view_* methods by the client result in
> perspective argument in view_* methods being None.
> 
> I have attached a complete working example of a client and server that
> succinctly illustrates this issue.
> 
> Question: Is there a way to distribute un-asked for references to
> Viewables that properly get the perspective argument in their view_*
> methods?

So, this strikes me as incredibly subtle, and likely a bug, but the fix is not immediately obvious to me.

Viewable objects are associated with their perspective when they are serialized.  They are associated with the perspective which is serializing them.

The "mind" object, passed by the client during the login process, can be just about anything - but one property that all "mind" objects share is that they are serialized *before authentication even occurs*, so there is no Avatar object and therefore no perspective around.  Therefore the ViewPoint which gets stored in the remote reference cache will have a perspective of None, and all subsequent calls made to that reference will have no perspective.

One way to fix this is to manually construct a ViewPoint rather than a Viewable and pass that to the client.  But I do think that we should find a way to make your use-case work, to, or at the very least document the reasons why it doesn't in a comprehensible way...

It's been a *very* long time since I took such a hard look at PB.  Good catch!

-glyph



More information about the Twisted-Python mailing list