Commit 2e841bf
fix(risk_acceptance): stop the expiration job aborting on an unattached risk acceptance (#15376)
* fix(risk_acceptance): stop the expiration job aborting on an unattached risk acceptance
`expiration_handler` raised `AttributeError: 'NoneType' object has no attribute
'product'` and aborted the whole run whenever it reached a risk acceptance that no
engagement points at. `Risk_Acceptance.engagement` is a property over a many-to-many
used as a one-to-many, so it returns None in that state, and both halves of the job
dereferenced it unconditionally while building the notification.
Impact was not limited to the one bad row: every risk acceptance later in the batch was
left unhandled, and because `expiration_date_warned` is only set after the notification,
the same risk acceptance was re-selected and failed the job again on every subsequent run.
Resolve the engagement once through `engagement_to_notify_about()`, which logs and
returns None when there is none, and skip only the notification in that case. The expiry
itself, the finding reactivation and the JIRA comments still happen, and the heads-up
path now marks the risk acceptance as warned either way so it stops being re-selected.
Adds two regression tests covering the warning path and the expiry path; both reproduce
the reported traceback before the change.
* fix(risk_acceptance): derive the notification engagement from the accepted findings
The previous commit stopped the crash but skipped the expiration notification whenever
`Risk_Acceptance.engagement` was empty. That is too blunt: an empty engagement relation
is a normal state for a populated risk acceptance, not a sign there is nobody to notify.
`RiskAcceptanceSerializer.create` only attaches an engagement when the risk acceptance
already has findings; `_accept_risks` and the SonarQube status sync never attach one;
and the Pro plugin tracks the association on its own model rather than on
`Engagement.risk_acceptance`. Skipping on an empty relation would therefore have dropped
expiration notifications for whole classes of risk acceptance that have findings, a
product, and users expecting to hear about them.
Fall back to the engagement of an accepted finding instead - the same derivation
`RiskAcceptanceSerializer` already uses to attach an engagement on create and to repair
an orphan on update. Only a risk acceptance with neither an engagement nor findings is
skipped, because the notification names a product and links to a per-engagement URL and
neither can be produced from an empty one.
Tests now cover the three cases separately: engagement link missing but findings present
(notification still sent, addressed via the derived engagement, asserted on both the
engagement and the product), no engagement and no findings (skipped, still marked warned
so it is not re-selected), and the same on the expiry half. All three fail against
unmodified `bugfix` at helper.py:54 and helper.py:203.
---------
Co-authored-by: DefectDojo Bot <bot@defectdojo.com>1 parent c603cd9 commit 2e841bf
2 files changed
Lines changed: 202 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
19 | 52 | | |
20 | 53 | | |
21 | 54 | | |
| |||
49 | 82 | | |
50 | 83 | | |
51 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
52 | 90 | | |
53 | 91 | | |
54 | | - | |
| 92 | + | |
55 | 93 | | |
56 | 94 | | |
57 | | - | |
58 | | - | |
59 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
60 | 98 | | |
61 | 99 | | |
62 | 100 | | |
| |||
198 | 236 | | |
199 | 237 | | |
200 | 238 | | |
201 | | - | |
202 | | - | |
203 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
204 | 244 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
209 | 249 | | |
210 | 250 | | |
211 | 251 | | |
| 252 | + | |
| 253 | + | |
212 | 254 | | |
213 | 255 | | |
214 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
299 | 300 | | |
300 | 301 | | |
301 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 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 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
0 commit comments