Passing session to Quirrel queue #2641
-
Here's the workflow I'm trying to implement:
I need to pass in the context to the Quirrel queue in order to save records to my database. But when I try, I got the error "TypeError: Converting circular structure to JSON". It seems like calling Object.stringify on the context object that I'm passing into the queue has a circular reference in it. Does anyone have any thoughts? Do I need to use something other than the mutator that requires the session context? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
cc @Skn0tt |
Beta Was this translation helpful? Give feedback.
-
You didn't describe the context object you were trying to serialize, but I think you'd be better off specifying the exact attributes from the session data that the job must have in order to run rather than trying to serialize everything. Not only is that going to serialize a lot more data than you need and give you circular reference errors like this, but even if you deleted all of the circular keys you identified from the object today, there's no guarantee that a new circular key wouldn't get added to it tomorrow. If you pick and choose the input parameters that you send to the job, then you can avoid this entire category of errors. |
Beta Was this translation helpful? Give feedback.
-
Hi, Quirrel guy here 👋 2nd what @MrLeebo says. In order to persist a payload in the the queue, Quirrel needs to serialize it. The context object is not serializable. You can, however, extract the important information from the context object, for example the ID of the requesting user, and put only that into the payload. |
Beta Was this translation helpful? Give feedback.
-
You could extract your DB insertion logic into a function and call that from both your mutation and the Queue.
…On 10. Aug 2021, 15:21 +0200, Leo Guinan ***@***.***>, wrote:
Ok, that makes a lot of sense.
So it sounds like I shouldn't try to use the mutator to do the db insert because that requires me to pass the context along from the request (I believe to be able to ensure that the user has the correct permissions).
I'll have to take a look at how I can do the db insert a different way.
Thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
You didn't describe the context object you were trying to serialize, but I think you'd be better off specifying the exact attributes from the session data that the job must have in order to run rather than trying to serialize everything. Not only is that going to serialize a lot more data than you need and give you circular reference errors like this, but even if you deleted all of the circular keys you identified from the object today, there's no guarantee that a new circular key wouldn't get added to it tomorrow.
If you pick and choose the input parameters that you send to the job, then you can avoid this entire category of errors.