Class discoverability

12 views
Skip to first unread message

Ubaldo Huerta

unread,
Aug 13, 2011, 9:03:51 AM8/13/11
to google-prot...@googlegroups.com
Say I want to define a message that includes another message (in case you'd like to have a list, for example, but it's irrelevant)

class MyMessage(messages.Message):

    rewards = messages.MessageField(MyOtherMessage, 1, repeated=True)


Well, this works fine only if MyOtherMessage is not a nested class in a module. 

# This works fine
class MyOtherMessage(messages.Message):
   ......

class Foo:
   # This doesn't work
   class MyOtherMessage(messages.Message):
   ......
   
Not that using a string form for MyMessage won't help you either
class MyMessage(messages.Message):

     # This doesn't work either
    rewards = messages.MessageField("Foo.MyOtherMessage", 1, repeated=True)

Rafe Kaplan

unread,
Aug 14, 2011, 8:44:27 PM8/14/11
to google-prot...@googlegroups.com
It should work if MyOtherMessage is nested within another message.
For example, if Foo is a message.

The reason that it cannot work otherwise is that the name you are
passing in is meant to be a protorpc fully qualified name. It needs
to be the same name (relative to MyMessage or absolute) that the
client will use. That means protorpc explicitly rejects Foo as a
container for the class in this case.

Reply all
Reply to author
Forward
0 new messages