Skip to content

Commit a166f49

Browse files
committed
BUG26847553: Fix AttributeError when using pure Python Protobuf
Using a value of type list when setting an attribute in a Message object throws an AttributeError. This patch fix this issue by testing the value type and using the .extend() method for list type values. This patch also adds the encoding of string values types to bytes when using Python 3.
1 parent 06adc79 commit a166f49

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/mysqlx/protobuf/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"""This module contains the implementation of a helper class for MySQL X
2525
Protobuf messages."""
2626

27-
from mysqlx.compat import NUMERIC_TYPES, STRING_TYPES, BYTE_TYPES
27+
from mysqlx.compat import PY3, NUMERIC_TYPES, STRING_TYPES, BYTE_TYPES
28+
from mysqlx.helpers import encode_to_bytes
2829

2930

3031
_SERVER_MESSAGES_TUPLES = (
@@ -232,8 +233,12 @@ def __setattr__(self, name, value):
232233
self._msg[name] = value.get_message() \
233234
if isinstance(value, Message) else value
234235
else:
235-
if isinstance(value, (NUMERIC_TYPES, STRING_TYPES, BYTE_TYPES)):
236+
if PY3 and isinstance(value, STRING_TYPES):
237+
setattr(self._msg, name, encode_to_bytes(value))
238+
elif isinstance(value, (NUMERIC_TYPES, STRING_TYPES, BYTE_TYPES)):
236239
setattr(self._msg, name, value)
240+
elif isinstance(value, list):
241+
getattr(self._msg, name).extend(value)
237242
elif isinstance(value, Message):
238243
getattr(self._msg, name).MergeFrom(value.get_message())
239244
else:

0 commit comments

Comments
 (0)