Skip to content

Commit

Permalink
Require bytes or strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwb authored Sep 30, 2024
1 parent 3d90cff commit 68263fc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sdks/python/apache_beam/yaml/yaml_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,13 @@ def convert_to_bytes(row):
output = getattr(row, field_names[0])
if isinstance(output, bytes):
return output
try:
return str(output).encode('utf-8')
except Exception as e:
elif isinstance(output, str):
return output.encode('utf-8')
else:
raise ValueError(
f"Cannot encode payload for WriteToPubSub. "
f"Must be valid string or bytes object. {e}")
f"Expected be valid string or bytes object, "
f"got {repr(output)} of type {type(output}.")

return convert_to_bytes
elif format == 'JSON':
Expand Down

0 comments on commit 68263fc

Please sign in to comment.