Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update function returns datetimes as string #240

Open
edi-spaghetti opened this issue Nov 27, 2020 · 0 comments
Open

Update function returns datetimes as string #240

edi-spaghetti opened this issue Nov 27, 2020 · 0 comments

Comments

@edi-spaghetti
Copy link

edi-spaghetti commented Nov 27, 2020

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant