Skip to content

Commit d120140

Browse files
authored
Don't use __getstate__ for pickling for objects with a custom __reduce__. (#33157)
This fixes #33137
1 parent e939be3 commit d120140

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

sdks/python/apache_beam/coders/coder_impl.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,9 @@ def encode_special_deterministic(self, value, stream):
500500
self.encode_to_stream(value.value, stream, True)
501501
except Exception as e:
502502
raise TypeError(self._deterministic_encoding_error_msg(value)) from e
503-
elif hasattr(value, "__getstate__"):
503+
elif (hasattr(value, "__getstate__") and
504+
# https://github.com/apache/beam/issues/33020
505+
type(value).__reduce__ == object.__reduce__):
504506
if not hasattr(value, "__setstate__"):
505507
raise TypeError(
506508
"Unable to deterministically encode '%s' of type '%s', "
@@ -510,9 +512,6 @@ def encode_special_deterministic(self, value, stream):
510512
stream.write_byte(NESTED_STATE_TYPE)
511513
self.encode_type(type(value), stream)
512514
state_value = value.__getstate__()
513-
if value is not None and state_value is None:
514-
# https://github.com/apache/beam/issues/33020
515-
raise TypeError(self._deterministic_encoding_error_msg(value))
516515
try:
517516
self.encode_to_stream(state_value, stream, True)
518517
except Exception as e:

0 commit comments

Comments
 (0)