From 94772806b2ff158268924d2f431778dba12e8b74 Mon Sep 17 00:00:00 2001 From: mueller-ma <22525368+mueller-ma@users.noreply.github.com> Date: Mon, 13 Jul 2026 15:00:22 +0200 Subject: [PATCH] Fix crash when editing rules with hyphenated predefined condition IDs Predefined condition identifiers created in Checkmk 2.4 or earlier could contain hyphens (e.g. 'cond_host_monitoring-01'). The new rule catalog renderer passed these idents directly as SingleChoiceElement names, which requires valid Python identifiers, causing a ValueError when opening or editing any rule that referenced such a condition. Fix by using SingleChoiceExtended / SingleChoiceElementExtended (internal API) instead of the public SingleChoice / SingleChoiceElement for the predefined conditions list. The Extended variants do not validate names as Python identifiers. Refs: https://forum.checkmk.com/t/unable-to-edit-rules-when-explicit-hostname-contains-hyphens/59918 --- .werks/20201.md | 21 +++++++++++++++++++++ cmk/gui/watolib/rulesets.py | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .werks/20201.md diff --git a/.werks/20201.md b/.werks/20201.md new file mode 100644 index 00000000000..01df6cfa668 --- /dev/null +++ b/.werks/20201.md @@ -0,0 +1,21 @@ +[//]: # (werk v3) +# Fix crash when editing rules with predefined conditions whose ID contains hyphens + +key | value +---------- | --- +date | 2026-07-13T00:00:00+00:00 +version | 3.0.0b1 +class | fix +edition | community +component | wato +level | 1 +compatible | yes + +Previously, opening or editing a rule that referenced a predefined condition whose unique ID +contained a hyphen (e.g. `cond_host_monitoring-01`) caused a crash with the error: + +_ValueError: 'cond_host_monitoring-01' is not a valid, non-reserved Python identifier_ + +This affected predefined conditions created in Checkmk 2.4 or earlier that used hyphens in +their ID. The issue only appeared in the rule editor — the conditions themselves still matched +correctly at runtime. diff --git a/cmk/gui/watolib/rulesets.py b/cmk/gui/watolib/rulesets.py index d935c56f908..8c170835544 100644 --- a/cmk/gui/watolib/rulesets.py +++ b/cmk/gui/watolib/rulesets.py @@ -2452,10 +2452,10 @@ def _create_rule_conditions_catalog_topic( CascadingSingleChoiceElementAPI( name="predefined", title=Title("Predefined conditions"), - parameter_form=SingleChoiceAPI( + parameter_form=SingleChoiceExtendedAPI( title=Title("Predefined condition"), elements=[ - SingleChoiceElementAPI( + SingleChoiceElementExtendedAPI( name=n, title=Title("%(title)s") % {"title": t} ) for n, t in PredefinedConditionStore().choices()