Tested on python api v3.2.4, but haven't seen anything in 3.2.6 that would fix this.
When running the update function on a datetime field the return value is a string, rather than the datetime.datetime expected.
This string is also not compatible with plugging back in to further updates.
Example below;
import datetime
from tank_vendor.shotgun_api3.lib.sgtimezone import UTC
from tank.util import shotgun
utc_now = datetime.datetime.now(UTC())
sg = shotgun.create_sg_connection()
# update date field with utc date, returns as string
sg.update('PublishedFile', 433118, {'sg_accessed_at': utc_now})
>>> {'sg_accessed_at': '2020-11-27 09:52:29 UTC', 'type': 'PublishedFile', 'id': 433118}
# for comparison, find_one returns as datetime with tzinfo
sg.find_one('PublishedFile', [['id', 'is', 433118]], ['sg_accessed_at'])
>>> {'sg_accessed_at': datetime.datetime(2020, 11, 27, 9, 52, 29, tzinfo=<tank_vendor.shotgun_api3.lib.sgtimezone.LocalTimezone object at 0x7fdff227b8d0>), 'type': 'PublishedFile', 'id': 433118}
# plugging that string back into an update throws an error
sg.update('PublishedFile', 433118, {'sg_accessed_at': '2020-11-27 09:52:29 UTC'})
>>> Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 1435, in update
record = self._call_rpc("update", params)
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 3314, in _call_rpc
self._response_errors(response)
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 3619, in _response_errors
raise Fault(sg_response.get("message", "Unknown Error"))
Fault: Invalid date time format: 2020-11-27 09:52:29 UTC. Correct format is 2011-01-21T13:26:09Z (UTC) or 2011-01-21T13:26:09-07:00 (UTC Offset)
# note, the recommended format also throws an error
sg.update('PublishedFile', 433118, {'sg_accessed_at': '2020-11-27T09:52:29Z (UTC)'})
>>> Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 1435, in update
record = self._call_rpc("update", params)
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 3314, in _call_rpc
self._response_errors(response)
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 3619, in _response_errors
raise Fault(sg_response.get("message", "Unknown Error"))
Fault: Invalid date time format: 2020-11-27T09:52:29Z (UTC). Correct format is 2011-01-21T13:26:09Z (UTC) or 2011-01-21T13:26:09-07:00 (UTC Offset)
Tested on python api v3.2.4, but haven't seen anything in 3.2.6 that would fix this. When running the update function on a datetime field the return value is a string, rather than the datetime.datetime expected. This string is also not compatible with plugging back in to further updates.
Example below;