Solved! 
I had to call the MessageFactory at module level instead of at 
instance/object level. 

Solution
msg_class = message_factory.GetMessageClass(type_desc)

On Monday, January 5, 2026 at 11:05:08 AM UTC-7 Pablo Camacho wrote:

> 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)
> ```
>
> On Monday, January 5, 2026 at 6:49:43 AM UTC-7 Pablo Camacho wrote:
>
>> 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. 
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/protobuf/f13c370b-e521-4094-974c-7a9f6af99314n%40googlegroups.com.

Reply via email to