# Inconsistency between query on peer and transact

**URL:** <https://forum.datomic.com/t/inconsistency-between-query-on-peer-and-transact/548>\
**Category:** Datomic Pro\
**Created:** [July 17, 2018, 4:03am UTC](https://forum.datomic.com/t/inconsistency-between-query-on-peer-and-transact/548 "2018-07-17T04:03:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![souenzzo](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/souenzzo/32/57_2.png) [@souenzzo](https://forum.datomic.com/u/souenzzo)\
**Post date:** [July 17, 2018, 4:03am UTC](https://forum.datomic.com/t/inconsistency-between-query-on-peer-and-transact/548/1 "2018-07-17T04:03:19Z")

</div>

Hello  
I’m on “classic peer”  
I have a datomic function `:empty-query?` that I use as transaction function

```auto
(def empty-query?
  (d/function '{:lang :clojure
                :requires [[datomic.api :as d]]
                :params [db query & args]
                :code (when-not (->> (into [db] args)
                                         (hash-map :query query :args)
                                         (d/query)
                                         (empty?))
                            (throw (ex-info "FAIL" {})))}))

```

But some queries produce different result’s on `peer` and on `transactor`  
For example

```auto
'[:find ?e
  :in $ ?ignore-set
  :where
  [?e :app/foo]
  (not [(contains? ?ignore-set ?e)])]

```

on `peer`(d/with and d/transact on “mem”) works “as expected”  
on `transact`(d/transact on “dev”) always return “empty?”  
Then I changed to

```auto
'[:find ?e
  :in $ ?ignore-set
  :where
  [?e :app/foo]
  [(contains? ?ignore-set ?e) ?q]
  [(ground false) ?q]]

```

That second one always returns the same results (“as expected”) on transactor and on peer.  
Is it a bug?

---

<div class="post-metadata">

**Author:** ![marshall](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/marshall/32/48_2.png) [@marshall](https://forum.datomic.com/u/marshall)\
**Post date:** [July 18, 2018, 1:24pm UTC](https://forum.datomic.com/t/inconsistency-between-query-on-peer-and-transact/548/2 "2018-07-18T13:24:22Z")

</div>

I don’t understand what exactly fails here.  
You’re not invoking your `empty-query?` function in either of the query examples you provide.

---

<div class="post-metadata">

**Author:** ![souenzzo](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/souenzzo/32/57_2.png) [@souenzzo](https://forum.datomic.com/u/souenzzo)\
**Post date:** [July 18, 2018, 1:56pm UTC](https://forum.datomic.com/t/inconsistency-between-query-on-peer-and-transact/548/3 "2018-07-18T13:56:00Z")

</div>

Thnks @marshall .  
I’m using `:empty-query` as a `Transaction function`.  
Example of use

```auto
(let [query '[:find ?e :where [?e :foo/bar]]]
  (d/transact conn [[:empty-query query][:db/add "foo" :foo/bar "bar"]])

```

But some queries has different behaviors when running in `datomic:mem` and `datomic:dev`.  
When I say “on `peer` (d/with and d/transact on \“mem\”) works \“as expected\”” I’m saying that I have a `tx-data` that contains a `[:empty-query ...]` and when I `transact` this `tx-data` on `datomic:mem` or make a `d/with` on `datomic:dev`, it works as I expected (fail the tx, for example). But when I `d/transact` to `datomic:dev`, then the transaction is completed successfully.

A repl-driven explanation

```auto
(def mem-conn (create-and-install-sample-set-1 "datomic:mem://foo"))
(def dev-conn (create-and-install-sample-set-1 "datomic:dev://localhost:4334/foo"))
(def tx-data [[:empty-query ....] [:db/add ...]])
;; I expect that this tx-data fails becaulse `[:empty-query ...]` will find results 
(d/with (d/db mem-conn) tx-data) ;;; fail/throws; as expected
(d/with (d/db dev-conn) tx-data) ;;; fail/throws; as expected
@(d/transact mem-conn tx-data) ;;; fail/throws; as expected
@(d/transact dev-conn tx-data) ;; transact with success.; ???!!!????!!!

```

Then I change the query in `:emtpty-query` from (first query on first post) to (second query on first post). I think that are both equivalents. But just the first do the issue. The second works “as expected” on “4” cenarios.

---

<div class="post-metadata">

**Author:** ![marshall](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/marshall/32/48_2.png) [@marshall](https://forum.datomic.com/u/marshall)\
**Post date:** [July 18, 2018, 4:33pm UTC](https://forum.datomic.com/t/inconsistency-between-query-on-peer-and-transact/548/4 "2018-07-18T16:33:49Z")

</div>

For testing purposes on a `dev` transactor you should be able to include output statements (i.e. `println`) inside your transaction function and they will print to stdout in the terminal where you’re running your transactor.

I would suggest examining the arguments and the constructed query to determine why the query isn’t returning your expected result. In general, this type of issue arises when using a ‘remote’ transactor because the arguments to a transaction function arrive as a Java type in the remote case (`dev`), but not in the in-process case (`mem` and `with`).

---

<div class="post-metadata">

**Author:** ![souenzzo](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/souenzzo/32/57_2.png) [@souenzzo](https://forum.datomic.com/u/souenzzo)\
**Post date:** [July 18, 2018, 6:07pm UTC](https://forum.datomic.com/t/inconsistency-between-query-on-peer-and-transact/548/5 "2018-07-18T18:07:03Z")

</div>

Already did that  
`(prn [x (class x)])` all the things  
The only relevant difference that I found was that `(not [(contains? ?ignore-set ?e)])` turns into `[not [[contains? ?ignore-set ?e]]]`.

The main problem is that in my tests on `mem` it works and when I go production, it fail. And it is for concurrency problems.  
I will make a repo to reproduce ASAP

---

<div class="post-metadata">

**Author:** ![souenzzo](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/souenzzo/32/57_2.png) [@souenzzo](https://forum.datomic.com/u/souenzzo)\
**Post date:** [July 22, 2018, 2:15am UTC](https://forum.datomic.com/t/inconsistency-between-query-on-peer-and-transact/548/6 "2018-07-22T02:15:20Z")

</div>

@marshall

Easy gist to reproduce

> <https://gist.github.com/souenzzo/c7b5a5434d4c04efcc58802c81b46023>

---

<div class="post-metadata">

**Author:** ![marshall](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/marshall/32/48_2.png) [@marshall](https://forum.datomic.com/u/marshall)\
**Post date:** [July 23, 2018, 1:19pm UTC](https://forum.datomic.com/t/inconsistency-between-query-on-peer-and-transact/548/7 "2018-07-23T13:19:12Z")

</div>

Thanks for providing this.  
We’re looking into the behavior.

---

<div class="post-metadata">

**Author:** ![souenzzo](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/souenzzo/32/57_2.png) [@souenzzo](https://forum.datomic.com/u/souenzzo)\
**Post date:** [July 27, 2018, 1:38pm UTC](https://forum.datomic.com/t/inconsistency-between-query-on-peer-and-transact/548/8 "2018-07-27T13:38:07Z")

</div>

@stu @marshall  
Any news about that?  
It will be fixed? There is a issue/tracking thing?
