{"action":"opened","issue":{"url":"https://api.github.com/repos/infinitered/cdq/issues/87","labels_url":"https://api.github.com/repos/infinitered/cdq/issues/87/labels{/name}","comments_url":"https://api.github.com/repos/infinitered/cdq/issues/87/comments","events_url":"https://api.github.com/repos/infinitered/cdq/issues/87/events","html_url":"https://github.com/infinitered/cdq/issues/87","id":64150729,"number":87,"title":"CDQ#save throws an error given a created_at field that's not a DateTime","user":{"login":"paddingtonsbear","id":2347012,"avatar_url":"https://avatars.githubusercontent.com/u/2347012?v=3","gravatar_id":"","url":"https://api.github.com/users/paddingtonsbear","html_url":"https://github.com/paddingtonsbear","followers_url":"https://api.github.com/users/paddingtonsbear/followers","following_url":"https://api.github.com/users/paddingtonsbear/following{/other_user}","gists_url":"https://api.github.com/users/paddingtonsbear/gists{/gist_id}","starred_url":"https://api.github.com/users/paddingtonsbear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paddingtonsbear/subscriptions","organizations_url":"https://api.github.com/users/paddingtonsbear/orgs","repos_url":"https://api.github.com/users/paddingtonsbear/repos","events_url":"https://api.github.com/users/paddingtonsbear/events{/privacy}","received_events_url":"https://api.github.com/users/paddingtonsbear/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-25T02:16:20Z","updated_at":"2015-03-25T02:16:20Z","closed_at":null,"body":"So I have the following entity \r\n```ruby\r\nentity \"Post\" do\r\n  integer32 :post_id\r\n  integer32 :created_at \r\nend\r\n```\r\nas you can see `created_at` is not a DateTime but an integer. Every time I run the following code\r\n```ruby\r\ncdq.background do\r\n  # only save the current thread's stack\r\n  cdq.save(always_wait: true)\r\n\r\n  # save the whole stack (optional)\r\n  cdq.contexts.on(:main) { cdq.save }\r\nend\r\n```\r\nI run into this error\r\n```ruby\r\n*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable\r\n type of value for attribute: property = \"created_at\"; desired type = NSNumber; given type = Time;\r\n value = 2015-03-25 01:38:49 +0000.'\r\n```\r\n\r\nDigging around I found this method in the `ContextManager`\r\n```ruby\r\ndef set_timestamps\r\n  now = Time.now\r\n\r\n  current.insertedObjects.allObjects.each do |e|\r\n    e.created_at = now if e.respond_to? :created_at=\r\n    e.updated_at = now if e.respond_to? :updated_at=\r\n  end\r\n\r\n  current.updatedObjects.allObjects.each do |e|\r\n    e.updated_at = now if e.respond_to? :updated_at=\r\n  end\r\nend\r\n```\r\nI think it would be a good idea to check the attribute type before setting `created_at` and `updated_at`, also wouldn't this always override a JSON response received from an api\r\n```ruby\r\neg. \r\n{\r\n  post_id: 1,\r\n  created_at: Time.now.to_i # (Unix Time)\r\n}\r\n```\r\n"}}