Jump to content

Datetime Field ?


lukas g

Recommended Posts

Hello,

I need to sync parts my ftrack database with parts of my inhouse database. For this reason I need support for a timestamp (Date AND time) which gets updated when a field has last been changed.
How can i put datetime information into the ftrack database?
The custom_attributes support the date field and if i query it i receive an arrow object. But when i try to set it to a new datetime i can only set it with a date but not with a time information.

if i try to set it with time information i get an error:
ServerError: Server reported error: IntegrityError(Custom attribute value for "my_time_stamp" must be a valid date. Got '2018-06-28T18:13:14.043000'.)

 

Here is some code snippet:

my_object = session.query("MyObjectType where name is MyName").first()


my_time_stamp = my_object["custom_attributes"]["my_time_stamp"]
log.debug("My Time Stamp: {}".format(my_time_stamp)) # >>> 2018-06-28T00:00:00+00:00

arrow_now = arrow.utcnow()
log.debug("Arrow datetime: {}".format(arrow_now.datetime)) # >>> 2018-06-28 18:04:48.799000+00:00
log.debug("Arrow date: {}".format(arrow_now.date())) # >>> 2018-06-28

my_object["custom_attributes"]["my_time_stamp"] = arrow_now.date()

 

I hope someone can guide me to the right direction.

Best,

Lukas

Link to comment
Share on other sites

13 hours ago, lukas g said:

ServerError: Server reported error: IntegrityError(Custom attribute value for "my_time_stamp" must be a valid date. Got '2018-06-28T18:13:14.043000'.)

 

If you do not call .date() on the arrow_now, does it work then?

There is a 'Event' schema that can be used:

session.query('Event where parent_id is "fc625b24-fd16-11e3-9bfd-04011030cf01" order by created_at desc limit 1').one()

 

Link to comment
Share on other sites

Hi Mattias,

the event query tip was very helpful! Thanks a lot for that. Now i am able to compare all DB entries with each other based on their latest update :)

Regarding the arrow date issue. I was not able to get it to work with my custom attribute (But right now i don't rely on the custom date attribute anymore as i am using the nice event query)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...