AttributeError: whichOneof in google.generativeai after recent use - Function Calling Issue

I’m encountering an AttributeError: whichOneof error when using the google.generativeai library in my Flask application. This code was working correctly, but it suddenly started failing with this error. I’m using function calling with the Gemini model.

2025-03-01 17:10:30,370: Exception on /chat [POST]
Traceback (most recent call last):
File “/usr/local/lib/python3.10/site-packages/flask/app.py”, line 2077, in wsgi_app
response = self.full_dispatch_request()
File “/usr/local/lib/python3.10/site-packages/flask/app.py”, line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/home/grav/.local/lib/python3.10/site-packages/flask_cors/extension.py”, line 194, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File “/usr/local/lib/python3.10/site-packages/flask/app.py”, line 1523, in full_dispatch_request
rv = self.dispatch_request()
File “/usr/local/lib/python3.10/site-packages/flask/app.py”, line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File “/home/grav/mysite/flask_app.py”, line 316, in chat
bot_response = chat_with_model(user_id, user_message)
File “/home/grav/mysite/flask_app.py”, line 302, in chat_with_model
html_response = markdown.markdown(response.text)
File “/home/grav/.local/lib/python3.10/site-packages/google/generativeai/types/generation_types.py”, line 536, in text
part_type = protos.Part.pb(part).whichOneof(“data”)
AttributeError: whichOneof

Seems like the issue happens when creating complex responses. The .text does not know how to handle new part types. You need to iterate over the parts and handle FunctionCall objects by yourself.

Similar issue has been posted by users in the python-sdk gitHub. I am sharing issue link for your reference.