{"record":{"id":"f223cd5c54778cc3","repo":"stamparm/maltrail","slug":"no-version-assignment-in-core-settings-py","errorCode":null,"errorMessage":"[!] no VERSION assignment in core/settings.py","messagePattern":"\\[!\\] no VERSION assignment in core/settings\\.py","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"sensor/tools/bump_version.py","lineNumber":72,"sourceCode":"         r'^(VERSION\\s*=\\s*\")[^\"]*(\")', r'\\g<1>%s\\g<2>' % version),\n        (os.path.join(ROOT, \"sensor\", \"Cargo.toml\"),\n         r'^(version\\s*=\\s*\")[^\"]*(\")', r'\\g<1>%s\\g<2>' % cargo),\n        # anchored to the package entry: a bare ^version in a lock file would match every\n        # dependency in it\n        (os.path.join(ROOT, \"sensor\", \"Cargo.lock\"),\n         r'(name = \"maltrail-sensor\"\\nversion = \")[^\"]*(\")', r'\\g<1>%s\\g<2>' % cargo),\n        (os.path.join(ROOT, \"CITATION.cff\"),\n         r'^(version\\s*:\\s*\")[^\"]*(\")', r'\\g<1>%s\\g<2>' % version),\n        (os.path.join(ROOT, \"sensor\", \"src\", \"settings_gen.rs\"),\n         r'^(pub const VERSION: &str = \")[^\"]*(\";)', r'\\g<1>%s\\g<2>' % version),\n    ]\n\n\ndef current():\n    match = re.search(r'^VERSION\\s*=\\s*\"([^\"]+)\"',\n                      _read(os.path.join(ROOT, \"core\", \"settings.py\")), re.M)\n    if not match:\n        raise SystemExit(\"[!] no VERSION assignment in core/settings.py\")\n    return match.group(1)\n\n\ndef next_minor(version):\n    parts = version.split(\".\")\n    if len(parts) < 2 or not all(p.isdigit() for p in parts[:2]):\n        raise SystemExit(\"[!] cannot bump %r - expected 'major.minor'\" % version)\n    return \"%s.%d\" % (parts[0], int(parts[1]) + 1)\n\n\ndef apply(version, date_released=None):\n    \"\"\"Rewrite every file, or none of them.\"\"\"\n\n    planned = []\n    for path, pattern, repl in _edits(version):\n        text = _read(path)\n        new, n = re.subn(pattern, repl, text, flags=re.M)\n        # Exactly once. Zero means the file moved on and this script is now lying about","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/stamparm/maltrail/blob/77cfb06d7606506d101bbcec0786c77166c4255e/sensor/tools/bump_version.py#L54-L90","documentation":"bump_version.py reads the current version by regex-matching a top-level `VERSION = \"x.y\"` assignment in core/settings.py. If the regex finds no match, it aborts with this SystemExit. It throws because the tool cannot safely compute the next version without a canonical two-component VERSION assignment.","triggerScenarios":"Running `python sensor/tools/bump_version.py --next` (or --version) when core/settings.py has no line starting with `VERSION = \"...\"` (exact spacing/name per regex `^VERSION\\s*=\\s*\"([^\"]+)\"` in multiline mode).","commonSituations":"A refactor renamed the variable (e.g. CURRENT_VERSION), switched to single quotes, moved the version into a config file/pyproject.toml, added a comment prefix before VERSION, or core/settings.py is missing/stale in a build checkout.","solutions":["Open core/settings.py and restore a top-level two-component assignment like VERSION = \"0.5\".","Check the file path: the script resolves core/settings.py relative to its ROOT, so run it from a checkout that actually contains core/settings.py.","If the variable was renamed or quoted differently, either rename it back or update the regex in current() to match the new format."],"exampleFix":"// before (core/settings.py)\nMALTRAIL_VERSION = '0.5'\n// after\nVERSION = \"0.5\"","handlingStrategy":"validation","validationCode":"import re\ntext = open('core/settings.py').read()\nif not re.search(r'^VERSION\\s*=\\s*\"([^\"]+)\"', text, re.M):\n    raise RuntimeError('core/settings.py lacks a VERSION = \"x.y\" assignment')\n","typeGuard":"def has_version_assignment(text: str) -> bool:\n    return re.search(r'^VERSION\\s*=\\s*\"([^\"]+)\"', text, re.M) is not None\n","tryCatchPattern":"try:\n    bump_version.main(['--next'])\nexcept SystemExit as e:\n    if 'no VERSION assignment' in str(e):\n        fix_settings_version_file()\n","preventionTips":["Keep VERSION as the first line of core/settings.py with double quotes","Add a CI check that greps for the VERSION assignment before running release tooling","Never rename or re-quote the VERSION variable without updating bump_version.py"],"tags":["versioning","regex-match","config"],"backgroundTag":"missing-config-value","analyzedSha":"77cfb06d7606506d101bbcec0786c77166c4255e","analyzedAt":"2026-09-13T03:50:16.010Z","contentChangedAt":"2026-09-13T03:50:16.010Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}