Skip to content

Commit

Permalink
Don't use __getstate__ for pickling for objects with a custom __reduc…
Browse files Browse the repository at this point in the history
…e__. (#33157)

This fixes #33137
  • Loading branch information
robertwb authored Nov 18, 2024
1 parent e939be3 commit d120140
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions sdks/python/apache_beam/coders/coder_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,9 @@ def encode_special_deterministic(self, value, stream):
self.encode_to_stream(value.value, stream, True)
except Exception as e:
raise TypeError(self._deterministic_encoding_error_msg(value)) from e
elif hasattr(value, "__getstate__"):
elif (hasattr(value, "__getstate__") and
# https://github.com/apache/beam/issues/33020
type(value).__reduce__ == object.__reduce__):
if not hasattr(value, "__setstate__"):
raise TypeError(
"Unable to deterministically encode '%s' of type '%s', "
Expand All @@ -510,9 +512,6 @@ def encode_special_deterministic(self, value, stream):
stream.write_byte(NESTED_STATE_TYPE)
self.encode_type(type(value), stream)
state_value = value.__getstate__()
if value is not None and state_value is None:
# https://github.com/apache/beam/issues/33020
raise TypeError(self._deterministic_encoding_error_msg(value))
try:
self.encode_to_stream(state_value, stream, True)
except Exception as e:
Expand Down

0 comments on commit d120140

Please sign in to comment.