Why match parsing error?


We have Community Edition, Version 8.9.2 (build 46101) installed.

For the function below (Python 3.10)

import re

from sqlalchemy.exc import IntegrityError

def parse_integrity_error(err: IntegrityError) -> str:  # pragma: no cover
    pattern = r"Key \((?P<key>[^=]*)\)=\((?P<value>.*)\) (?P<status>[^\"]*)."

    err_message = err.orig.args[0]

    if m := re.search(pattern, err_message):
        key = m.group("key").strip()
        value = m.group("value").strip()
        status = m.group("status").strip()

        match status, key:
            case "already exists", "something":
                return f"Something {value} уже используется"
            case _:
                return f"{key} with value {value} {status}"

    return err_message

I have error:

ERROR: Unable to parse file: app/utils/db.py
ERROR: Parse error at line 16 column 14:
12: ()
13: value = m.group("value").strip()
14: status = m.group("status").strip()
 --> match status, key:
17: case "already exists", "something":
18: return f"Something {value} уже используется"
19: case _:
20: return f"{key} with value {value} {status}"
22: returnerr_message

What’s the problem with match? Does our version of SonarQube not support match operator?


Welcome to the community!

Your version is past EOL. You should upgrade to either the latest version or the current LTS at your earliest convenience. Your upgrade path is:

8.9.2 → 9.9.2 → 10.2.1 (last step optional)

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

From one version to the next, we make significant improvements in flagship languages, and that’s certainly true from one LTS to the next. If your error persists after upgrade, please come back to us.