Commit 1e1aac0
authored
Unique args: Guard against recursive types (#1090)
Also reported over in #1087, the unique module will overflow if
encountering a recursive type as it looks for unique keys to consider.
Here, try to be a little smarter about this, but not overly so by only
processing each type once. This means that inner recursive types always
just get treatment as a fully encoded JSON blob, but that's about as
good of a way to handle them as I can think of anyway.
Take this example:
type RecursiveType struct {
NotUnique string `river:"-"`
Recursive *RecursiveType `river:"unique"` // inner recursive type ignored by River
String string `river:"unique"`
}
type TaskJobArgs struct {
JobArgsStaticKind
Recursive RecursiveType `river:"unique"`
}
return TaskJobArgs{
JobArgsStaticKind: JobArgsStaticKind{kind: "worker_7"},
Recursive: RecursiveType{
Recursive: &RecursiveType{
String: "level2",
},
String: "level1",
},
}
Generated output is:
&kind=worker_7&args={"Recursive":{"Recursive":{"NotUnique":"","Recursive":null,"String":"level2"},"String":"level1"}}
Notably, we see "NotUnique" show up in the inner recursive type because
River has given up processing that and just treated the entire inner
"Recursive" as a JSON value. The outer type does not have "NotUnique"
because River saw the `river:"-"` annotation and knew not to treat it as
unique.1 parent 5b1fa35 commit 1e1aac0
3 files changed
Lines changed: 48 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
363 | 396 | | |
364 | 397 | | |
365 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| |||
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
| |||
97 | 108 | | |
98 | 109 | | |
99 | 110 | | |
100 | | - | |
| 111 | + | |
101 | 112 | | |
102 | 113 | | |
103 | 114 | | |
| |||
140 | 151 | | |
141 | 152 | | |
142 | 153 | | |
143 | | - | |
| 154 | + | |
144 | 155 | | |
145 | 156 | | |
146 | 157 | | |
| |||
0 commit comments