I have a really stupid problem that I
I have a really stupid problem that I cannot solve in the last hour.
I'm trying to use result of image mutation in another action
Here is the mutation
Here is the callsite code
I'm getting error
How I can pass the _id value that I got from one mutation into another through the action?
21 Replies
I think what I observe is that I can pass _id as a scalar, but when I try to do that for an array, convex doesn't like it.
I have read https://docs.convex.dev/using/document-ids#serializing-ids but I don't think it's covered there.
Document IDs | Convex Developer Hub
Create complex, relational data models using IDs.
I tried using
image._id.toString()
and then trying to re-hydrate it into a real ID on the other side, but I'm just getting a string ["[object Object]"]
hi this looks like
runMutation
is not deserializing the json into an object correctly. What's the context of the callsite? is runMutation
the result of a useMutation
or is this within an action or http endpoint?withing the action
ok so I solved (but I'd call it more like a workaround).
What I needed to do is to de-hydrate my id inside the first runMutation
and then pass it through the aciton as a string
and the re-hydrate it into ID
honestly that seems very non-intutive
interesting. this should be possible as you wrote it. i'm glad you found a workaround, but it seems like a bug on our side. i'll take a look
thank you!
I believe the root cause may be in the too strict checking of serialization of arrays
yep definitely a bug on our side. sorry about that. i'm sending the fix for review now, but it probably won't deploy today, so nice job finding a workaround π
for posterity (and to help construct workarounds), the issue is with the return values of queries and mutations when called from actions. simple objects, strings, arrays, and numbers should work. but complex types like
Id
, Set
, Map
, and bigint will not work until my fix deploysAs a bit of an aside -- it looks like some of the code you pasted could be a single mutation? (but also maybe there's a bunch of other code you omitted to give us a nice minimal snippet of your issue)
There is a side effect that I ommited
Glad to hear you are on it!
@vors Convex version 0.9.1 is out, including @lee's fix! You can upgrade to it with
npm install convex@0.9.1
amazing
nit: I think it should be
npm install -g convex@0.9.1
?
let me see can I revert the workaround backNot unless you want to install it globally!
typically with npm you install things at a project level, like poetry or pip-env for Python
hm something very weired happened
so I got afraid and instelled it globally π
that "fixed" it
oh sorry should be npx
ok still learning the ropes! Back to removing workaround
awesome, confirming that it works now!!! π
the important thing is that in the
package.json
in your project, it has a line like "convex": "^0.9.1",
βΒ that's the version that will be used in your project (if the library is installed in both places)
Thanks for reporting the issue and sorry for the trouble!of course, thank you for the amazing community support π
πββοΈ
I have another error in the same veins
I'm trying to pass an object into a
scheduler.runAfter
Yeah, we try to serialize the arguments as documents internally, which results in that issue. As workaround, try to pass just the id of the document (and then you can fetch it back) or whatever fields you need. Will work on a fix.
yeap did that... but seems clunky while I have a working object π
haha. Yeah, I can only imagine how clunky it is. Working on a fix.
Fixed has been deployed btw. Let us know if you still experience issues.
Thank you!