Deeply merge two error messages. The format of ``errors1`` and ``errors2`` matches the ``message`` parameter of :exc:`marshmallow.exceptions.ValidationError`.
(errors1, errors2)
| 35 | |
| 36 | |
| 37 | def merge_errors(errors1, errors2): # noqa: PLR0911 |
| 38 | """Deeply merge two error messages. |
| 39 | |
| 40 | The format of ``errors1`` and ``errors2`` matches the ``message`` |
| 41 | parameter of :exc:`marshmallow.exceptions.ValidationError`. |
| 42 | """ |
| 43 | if not errors1: |
| 44 | return errors2 |
| 45 | if not errors2: |
| 46 | return errors1 |
| 47 | if isinstance(errors1, list): |
| 48 | if isinstance(errors2, list): |
| 49 | errors1.extend(errors2) |
| 50 | return errors1 |
| 51 | if isinstance(errors2, dict): |
| 52 | errors2[SCHEMA] = merge_errors(errors1, errors2.get(SCHEMA)) |
| 53 | return errors2 |
| 54 | errors1.append(errors2) |
| 55 | return errors1 |
| 56 | if isinstance(errors1, dict): |
| 57 | if isinstance(errors2, dict): |
| 58 | for key, val in errors2.items(): |
| 59 | if key in errors1: |
| 60 | errors1[key] = merge_errors(errors1[key], val) |
| 61 | else: |
| 62 | errors1[key] = val |
| 63 | return errors1 |
| 64 | errors1[SCHEMA] = merge_errors(errors1.get(SCHEMA), errors2) |
| 65 | return errors1 |
| 66 | if isinstance(errors2, list): |
| 67 | return [errors1, *errors2] |
| 68 | if isinstance(errors2, dict): |
| 69 | errors2[SCHEMA] = merge_errors(errors1, errors2.get(SCHEMA)) |
| 70 | return errors2 |
| 71 | return [errors1, errors2] |
searching dependent graphs…