Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receiving bad :dispatch value #101

Open
paolapereira93 opened this issue Feb 19, 2025 · 5 comments
Open

Receiving bad :dispatch value #101

paolapereira93 opened this issue Feb 19, 2025 · 5 comments

Comments

@paolapereira93
Copy link

I am using re-graph to both mutate and query and I am facing an intermittent error in production. Here is an example:

re-frame: ignoring bad :dispatch value. Expected a vector, but got:{1 {:response {:data { ... }}}}

Here is a code similar to my application:

(defn my-callback
  "a callback"
  [_ _])

(defn- my-event
  [{:keys [db]} [_ params]]
  {:db db
   :dispatch [::re-graph/mutate {:instance-id :auth
                                 :id          (random-uuid)
                                 :query       my-query
                                 :callback    [::my-callback] ;; if callback is nil, the same error is raised
                                 :variables   {}]})

(reg-event-fx ::my-callback my-callback)
(reg-event-fx ::my-event  my-event)

I noticed that in some points of the re-graph code there are updates that could result in that error, like in here:

(update callback 1 assoc :response response)

Looking at this I can imagine why passing no callback raises the error, since (update nil 1 assoc :response {}) is {1 {:response {}}}. But I can not see how passing a callback can result in this. Also, it would be very useful to be able to omit the callback function in some cases.

@oliyh
Copy link
Owner

oliyh commented Feb 19, 2025

Hi,

What version of re-graph and re-frame are you using?

Cheers

@paolapereira93
Copy link
Author

paolapereira93 commented Feb 20, 2025

Here is how I am importing both:

re-frame/re-frame {:mvn/version "1.4.3"}
re-graph/re-graph {:mvn/version "0.2.0" :exclusions [re-graph.hato/re-graph.hato]}

Thank you!

@oliyh
Copy link
Owner

oliyh commented Feb 20, 2025

Thanks, I've looked into this a bit but not found anything yet. One thing I can try is to update re-frame on re-graph and run the tests to see if something changed in re-frame.

Are you using websockets or http to talk to the server?

Thanks

@oliyh
Copy link
Owner

oliyh commented Feb 20, 2025

Hi,

Are you sure you don't have a bad event handler that is wiping out the db? re-graph registers the callback against the query id, in order to dispatch it when it receives a response. If it got wiped out you'd probably see the error you get here, and that might also explain how it could be intermittent.

I upgraded most of the deps and all the tests still pass, so I don't think it's that.

Cheers

@paolapereira93
Copy link
Author

Hi,
I am using a http server.

I reviewed my code several times. With your suggestion in mind, I noticed a point of improvement. Which was returning an empty map of effects in my callback event.

Before:

(defn my-callback
  "a callback"
  [_ _])

Now:

(defn my-callback
  "a callback"
  [_ _]
  {})

But the error continues to occur in this version. I can not see how this can wip out the db in this case, since my callback event has no effects in it.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants