gemini-code-assist[bot] commented on code in PR #38985:
URL: https://github.com/apache/beam/pull/38985#discussion_r3422662050


##########
sdks/python/apache_beam/yaml/yaml_io.py:
##########
@@ -393,14 +399,18 @@ def mapper(msg):
           values[attr] = msg.attributes[attr]
       if attributes_map:
         values[attributes_map] = msg.attributes
+      if publish_time_field:
+        values[publish_time_field] = Timestamp.from_utc_datetime(
+            msg.publish_time)

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   In production, `PubsubMessage.publish_time` is already a `Timestamp` object 
(from `apache_beam.utils.timestamp`), not a `datetime.datetime` object. Calling 
`Timestamp.from_utc_datetime` on it will raise an `AttributeError` because 
`Timestamp` does not have the datetime attributes expected by 
`from_utc_datetime`.\n\nUsing `Timestamp.of` is much safer and more robust as 
it seamlessly handles both `Timestamp` and `datetime.datetime` objects (which 
also keeps your unit tests passing).
   
   ```python
           values[publish_time_field] = Timestamp.of(msg.publish_time)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to