[Debug] fix #10313: FlattenException not found

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10313
| License       | MIT
| Doc PR        | none

Note that this patch should be ignored while merging into 2.5/master (it will conflict because 2.5/master has a much stronger workaround, not suitable for a minor release IMHO).