Repository navigation
Commit f0c5a80
committed
Sort extra keys when formatting ForbiddenExtraKeysError
`ForbiddenExtraKeysError.extra_fields` is a `set`, and `format_exception`
in src/cattrs/v.py joined it directly, so `transform_error` put the extra
keys in whatever order that set happened to iterate in. String hashing is
randomized per process, so the message text changed from run to run once
more than one extra key was present, which breaks anything that compares
or snapshots the output of `transform_error`.
`ForbiddenExtraKeysError.__str__` in src/cattrs/errors.py already sorts
the same set, so the two renderings of one error disagreed as well.
Sort the keys in `format_exception` too, and add a regression test with
five extra keys, since the existing test only used one and could not
observe the ordering.1 parent df4e4bb commit f0c5a80
3 files changed
Lines changed: 27 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
109 | 130 | | |
110 | 131 | | |
111 | 132 | | |
| |||
0 commit comments