Strange error. MessageFactory object has no attribute GetMessageClass.

18 views
Skip to first unread message

Pablo Camacho

unread,
Jan 5, 2026, 8:49:43 AM (6 days ago) Jan 5
to Protocol Buffers
Hi,

I am trying to update python code to use a newer protobuf version: 6.33.2. 

I replaced GetPrototype with GetMessageClass.

I get this error.
AttributeError: 'MessageFactory' object has no attribute 'GetMessageClass'

I believe that GetMessageClass is supposed to be defined in message factory since version 4. I am confused about why I get this error.

What else could be causing this error? What should I look into?

Also, the protobuf files were made with an older version of protobuf. Would there be problems with trying to use a newer version of protobuf to read protobuf files made by an older version of protobuf? 

protoc version: libprotoc 33.1
python version: 3.10.12
protobuf version: 6.33.2. 

Pablo Camacho

unread,
Jan 5, 2026, 1:05:08 PM (6 days ago) Jan 5
to Protocol Buffers
More information on this error. 

I am using a python virtual environment. 

<path to virtual environment>/lib/python3.10/site-packages/google/protobuf/message_factory.py
Message Factory does exist in the python virtual environment. 
GetMessageClass function is defined in the message_factory.py file.

```
def GetMessageClass(descriptor):
  """Obtains a proto2 message class based on the passed in descriptor.

  Passing a descriptor with a fully qualified name matching a previous
  invocation will cause the same class to be returned.

  Args:
    descriptor: The descriptor to build from.

  Returns:
    A class describing the passed in descriptor.
  """
  concrete_class = getattr(descriptor, '_concrete_class', None)
  if concrete_class:
    return concrete_class
  return _InternalCreateMessageClass(descriptor)
```

Pablo Camacho

unread,
Jan 5, 2026, 1:44:21 PM (6 days ago) Jan 5
to Protocol Buffers
Solved! 
I had to call the MessageFactory at module level instead of at instance/object level. 

Solution
msg_class = message_factory.GetMessageClass(type_desc)
Reply all
Reply to author
Forward
0 new messages