Commit 1e36143
Fix PATCH conflicts when
At present all PATCH requests for resources that have a `meta.version`
attribute will fail with ErrConflict because the PatchService.Do()
method incorrectly mutates the current resource instead of its
replacement.
This error was not caught by existing unit tests because they do not set
a `meta.version` attribute and db.Memory().Replace() has the following
check:
version := ref.MetaVersionOrEmpty()
if len(version) > 0 && m.db[id].MetaVersionOrEmpty() != version {
return spec.ErrConflict
}
This has the effect of permitting replacements when there is no version
present -- which is the case for the existing unit tests **but not real
APIs**. Simply adding a `meta.version` attribute to unit tests (as in
this commit) yields failures like as the following:
=== RUN TestPatchService/TestDo/patch_to_make_a_difference
patch_test.go:99:
Error Trace: patch_test.go:99
patch_test.go:366
Error: Expected nil, but got: &spec.Error{Status:412, Type:"conflict"}
Test: TestPatchService/TestDo/patch_to_make_a_difference
An identical fix was originally proposed by @zakirhussain in imulab#80. This
commit expands on that work to include unit test changes to catch a
regression and (hopefully) a better explanation on the underlying cause
of the issue.
Co-authored-by: Zakir Hussain <pro.zakir24@gmail.com>
Signed-off-by: Aaron Jacobs <aaron.jacobs@rstudio.com>meta.version is present.1 parent fec7838 commit 1e36143
2 files changed
+43
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
| |||
90 | 97 | | |
91 | 98 | | |
92 | 99 | | |
| 100 | + | |
93 | 101 | | |
94 | 102 | | |
95 | 103 | | |
| |||
105 | 113 | | |
106 | 114 | | |
107 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
108 | 123 | | |
109 | 124 | | |
110 | 125 | | |
| |||
143 | 158 | | |
144 | 159 | | |
145 | 160 | | |
| 161 | + | |
146 | 162 | | |
147 | 163 | | |
148 | 164 | | |
| |||
153 | 169 | | |
154 | 170 | | |
155 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
156 | 179 | | |
157 | 180 | | |
158 | 181 | | |
| |||
200 | 223 | | |
201 | 224 | | |
202 | 225 | | |
| 226 | + | |
203 | 227 | | |
204 | 228 | | |
205 | 229 | | |
| |||
215 | 239 | | |
216 | 240 | | |
217 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
218 | 249 | | |
219 | 250 | | |
220 | 251 | | |
| |||
255 | 286 | | |
256 | 287 | | |
257 | 288 | | |
| 289 | + | |
258 | 290 | | |
259 | 291 | | |
260 | 292 | | |
| |||
273 | 305 | | |
274 | 306 | | |
275 | 307 | | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
276 | 315 | | |
277 | 316 | | |
278 | 317 | | |
| |||
313 | 352 | | |
314 | 353 | | |
315 | 354 | | |
| 355 | + | |
316 | 356 | | |
317 | 357 | | |
318 | 358 | | |
| |||
0 commit comments