posh icon indicating copy to clipboard operation
posh copied to clipboard

Pull queries do not update if their nested entities change

Open seantempesta opened this issue 8 years ago • 7 comments

Ran into this bug today. I had a (pull conn '[*] eid) that wasn't updating when a nested entity within that pull changed. I'm guessing it's because the datom match pattern is just for the specified eid (and not all returned entities)?

Anyway, I setup an example showing the bug here: https://github.com/seantempesta/posh-bug

The jist of it is this:

(def schema {;; Contact component (shared across entities)
             :contact/email {:db/cardinality :db.cardinality/one}
             :contact/phone {:db/cardinality :db.cardinality/one}

             ;; Users
             :user/username {:db/unique      :db.unique/identity
                             :db/cardinality :db.cardinality/one}
             :user/contact  {:db/valueType   :db.type/ref
                             :db/cardinality :db.cardinality/one
                             :db/isComponent true}})
(def conn (d/create-conn schema))
(posh! conn)


(transact! conn [{:db/id         -1
                  :user/username "seantempesta"
                  :user/contact  {:db/id         -2
                                  :contact/phone "555-5555"
                                  :contact/email "[email protected]"}}])



;; -------------------------
;; Views

(defn home-page []
  (let [user (pull conn '[*] [:user/username "seantempesta"])
        phone (pull conn '[*] 2)]
    [:div [:h2 "Welcome to posh-bug!"]

     [:div [:h4 {} "User Entity"]
      [:h5 {} @user]]

     [:div [:h4 {} "Phone Entity"]
      [:h5 {} @phone]]

     [:input {:type     "button" :value "Remove phone number"
              :on-click #(transact! conn [[:db/retract 2 :contact/phone "555-5555"]])}]]))
screen shot 2017-04-30 at 11 44 37 am

seantempesta avatar Apr 30 '17 04:04 seantempesta

So, I'm really not familiar enough with Posh's internals to fix this. I thought I saw somewhere that Posh might bring back manual specification of listen patterns? At least then I could work around this bug.

seantempesta avatar May 22 '17 08:05 seantempesta

Temporary workaround. I found if you explicitly expand isComponent pull patterns the pull analyze picks up the changes.

So, in the example above, you'd have to do something like this:

(pull conn '[:db/id, :user/username, {:user/contact [:db/id, :contact/email, :contact/phone]}] 2)

seantempesta avatar May 22 '17 08:05 seantempesta

Yes; it should certainly be looking at isComponent attributes. I'm flagging as bug. Thanks for reporting.

metasoarous avatar May 22 '17 15:05 metasoarous

@seantempesta was that all you had to do? I've tried the explicit expansion, still no joy for my reactions

eoliphan avatar Nov 30 '17 14:11 eoliphan

@eoliphan: It worked for my scenario at that time. No idea if it's working now as I'm no longer using Posh.

seantempesta avatar Nov 30 '17 18:11 seantempesta

@seantempesta ok, thanks. Yeah, i'm looking at alternatives as well, I really wanted to use DS as I've got Datomic on the server, but probably will just go with specter and maps, etc. for now until I can maybe look at figuring out the posh code and doing some hacking.

eoliphan avatar Nov 30 '17 18:11 eoliphan

Hello guys! I've got the same issue with nested components. Are there some ways to solve this issue? I can try to help with it if someone has an idea how to fix this bug.

tkachenko1503 avatar Jan 18 '20 18:01 tkachenko1503