{"action":"created","issue":{"url":"https://api.github.com/repos/tonsky/datascript/issues/76","labels_url":"https://api.github.com/repos/tonsky/datascript/issues/76/labels{/name}","comments_url":"https://api.github.com/repos/tonsky/datascript/issues/76/comments","events_url":"https://api.github.com/repos/tonsky/datascript/issues/76/events","html_url":"https://github.com/tonsky/datascript/issues/76","id":72878389,"number":76,"title":"Upsert with tx-data in list format ","user":{"login":"dwwoelfel","id":476818,"avatar_url":"https://avatars.githubusercontent.com/u/476818?v=3","gravatar_id":"","url":"https://api.github.com/users/dwwoelfel","html_url":"https://github.com/dwwoelfel","followers_url":"https://api.github.com/users/dwwoelfel/followers","following_url":"https://api.github.com/users/dwwoelfel/following{/other_user}","gists_url":"https://api.github.com/users/dwwoelfel/gists{/gist_id}","starred_url":"https://api.github.com/users/dwwoelfel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwwoelfel/subscriptions","organizations_url":"https://api.github.com/users/dwwoelfel/orgs","repos_url":"https://api.github.com/users/dwwoelfel/repos","events_url":"https://api.github.com/users/dwwoelfel/events{/privacy}","received_events_url":"https://api.github.com/users/dwwoelfel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-03T22:50:41Z","updated_at":"2015-05-05T07:00:19Z","closed_at":null,"body":"It looks like upserts are only resolved for tx-data in the map format. Here's an example that demonstrates the problem:\r\n\r\n```\r\n(let [db (d/db-with (d/empty-db {:name  { :db/unique :db.unique/identity }})\r\n                    [{:db/id 1 :name \"Ivan\"}])]\r\n  (d/with db [[:db/add -1 :age 35]\r\n              [:db/add -1 :name \"Ivan\"]]))\r\n\r\n=> throws {:error :transact/unique, :attribute :name, :datom #datascript/Datom [2 :name Ivan 536870914 true]}\r\n```\r\n\r\nAdded a [test on my fork](https://github.com/dwwoelfel/datascript/commit/9c3c1369d24c82950d58b7c047121d40d1a4cb1e), which also [fails in CI](https://circleci.com/gh/dwwoelfel/datascript/9). "},"comment":{"url":"https://api.github.com/repos/tonsky/datascript/issues/comments/98975155","html_url":"https://github.com/tonsky/datascript/issues/76#issuecomment-98975155","issue_url":"https://api.github.com/repos/tonsky/datascript/issues/76","id":98975155,"user":{"login":"dwwoelfel","id":476818,"avatar_url":"https://avatars.githubusercontent.com/u/476818?v=3","gravatar_id":"","url":"https://api.github.com/users/dwwoelfel","html_url":"https://github.com/dwwoelfel","followers_url":"https://api.github.com/users/dwwoelfel/followers","following_url":"https://api.github.com/users/dwwoelfel/following{/other_user}","gists_url":"https://api.github.com/users/dwwoelfel/gists{/gist_id}","starred_url":"https://api.github.com/users/dwwoelfel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwwoelfel/subscriptions","organizations_url":"https://api.github.com/users/dwwoelfel/orgs","repos_url":"https://api.github.com/users/dwwoelfel/repos","events_url":"https://api.github.com/users/dwwoelfel/events{/privacy}","received_events_url":"https://api.github.com/users/dwwoelfel/received_events","type":"User","site_admin":false},"created_at":"2015-05-05T07:00:18Z","updated_at":"2015-05-05T07:00:18Z","body":"I can't say for sure yet whether it's a serious issue, still working through some edge cases. Making the outcome order-dependent is going to cause other problems, though. Here's an example resolving tempids with refs where changing the order will result in an exception:\r\n\r\n```\r\n(deftest test-upsert\r\n  (let [db (d/db-with (d/empty-db {:name  { :db/unique :db.unique/identity }\r\n                                   :friend { :db/type :db.type/ref }})\r\n                      [{:db/id 1 :name \"Ivan\"}\r\n                       {:db/id 2 :name \"Petr\"}])\r\n        touched (fn [tx e] (into {} (d/touch (d/entity (:db-after tx) e))))]\r\n    \r\n    ;; This test passes\r\n    (testing \"upsert with references\"\r\n      (let [tx (d/with db [{:db/id -2 :name \"Petr\"}\r\n                           {:db/id -1 :name \"Ivan\" :friend -2}])]\r\n        (is (= {:name \"Ivan\" :friend {:db/id 2}} (touched tx 1)))\r\n        (is (= {:name \"Petr\"} (touched tx 2)))))\r\n\r\n    ;; Changing the order causes it to fail with\r\n    ;;  {:error :transact/upsert, :attribute :name, :entity {:db/id 3, :name Petr}, :datom #datascript/Datom [2 :name Petr 536870913 true]}\r\n    (testing \"upsert with references, reversed order of txes, fails\"\r\n      (let [tx (d/with db [{:db/id -1 :name \"Ivan\" :friend -2}\r\n                           {:db/id -2 :name \"Petr\"}])]\r\n        (is (= {:name \"Ivan\" :friend {:db/id 2}} (touched tx 1)))\r\n        (is (= {:name \"Petr\"} (touched tx 2)))))))\r\n```"}}