Commit da120e5
authored
Fix ActiveRecord JSONB args (#60)
* Fix ActiveRecord inserting job args as JSONB strings instead of objects
The ActiveRecord driver passed the JSON-encoded args string directly to
the insert. ActiveRecord's JSONB type serializer JSON-encodes all values
on write, so a string like '{"job_num":1}' gets double-encoded into a
JSONB string literal rather than stored as a JSONB object.
Go workers then fail to unmarshal the double-encoded value:
json: cannot unmarshal string into Go value of type ...Args
Parse the encoded args to a Hash before insert so ActiveRecord
serializes it as a proper JSONB object. Add a deserialize_json helper
on read paths for backwards compatibility with existing fixture data.
* Expect JSONB object values on Ruby read paths, same as Go
Remove the deserialize_json helper that tolerated double-encoded string
values. ActiveRecord natively deserializes JSONB objects to Hashes, so
no parsing is needed. Update test fixtures to use Hash args matching
what ActiveRecord returns from properly stored JSONB objects.1 parent 37b3cd2 commit da120e5
3 files changed
Lines changed: 39 additions & 9 deletions
File tree
- driver
- riverqueue-activerecord
- lib
- spec
- riverqueue-sequel/spec
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
18 | 33 | | |
19 | 34 | | |
20 | 35 | | |
21 | 36 | | |
22 | | - | |
| 37 | + | |
23 | 38 | | |
24 | 39 | | |
25 | 40 | | |
| |||
56 | 71 | | |
57 | 72 | | |
58 | 73 | | |
59 | | - | |
| 74 | + | |
60 | 75 | | |
61 | 76 | | |
62 | 77 | | |
| |||
93 | 108 | | |
94 | 109 | | |
95 | 110 | | |
96 | | - | |
| 111 | + | |
97 | 112 | | |
98 | 113 | | |
99 | 114 | | |
| |||
124 | 139 | | |
125 | 140 | | |
126 | 141 | | |
127 | | - | |
| 142 | + | |
128 | 143 | | |
129 | 144 | | |
130 | 145 | | |
| |||
159 | 174 | | |
160 | 175 | | |
161 | 176 | | |
162 | | - | |
| 177 | + | |
163 | 178 | | |
164 | 179 | | |
165 | 180 | | |
| |||
197 | 212 | | |
198 | 213 | | |
199 | 214 | | |
200 | | - | |
| 215 | + | |
201 | 216 | | |
202 | 217 | | |
203 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
12 | 27 | | |
13 | 28 | | |
14 | 29 | | |
| |||
0 commit comments