Error converting to legacy rulespec 'foo' : replace() should be called on dataclass instances

CMK version: 2.4.0p6
OS version: docker

Error message:

2025-07-15 14:12:30,019 [20] [49849/MainThread] --- Starting ui-job-scheduler (Checkmk 2.4.0p6) ---
2025-07-15 14:12:37,369 [40] [49849/MainThread] Error converting to legacy rulespec 'foo' : replace() should be called on dataclass instances
Traceback (most recent call last):
  File "/omd/sites/cmk/lib/python3/cmk/gui/utils/rule_specs/registering.py", line 21, in register_plugin
    legacy_rulespec = convert_to_legacy_rulespec(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/cmk/lib/python3/cmk/gui/utils/rule_specs/legacy_converter.py", line 161, in convert_to_legacy_rulespec
    return _convert_to_legacy_check_parameter_rulespec(to_convert, edition_only, localizer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/cmk/lib/python3/cmk/gui/utils/rule_specs/legacy_converter.py", line 231, in _convert_to_legacy_check_parameter_rulespec
    item_spec, item_form_spec = _get_item_spec_maker(convert_condition, localizer)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/cmk/lib/python3/cmk/gui/utils/rule_specs/legacy_converter.py", line 1527, in _get_item_spec_maker
    item_form_with_title = dataclasses.replace(condition.item_form, title=condition.item_title)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/cmk/lib/python3.12/dataclasses.py", line 1559, in replace
    raise TypeError("replace() should be called on dataclass instances")
TypeError: replace() should be called on dataclass instances

My rule specification looks like this:

def _item_form():
    return String(
        title=Title("My Foo Name"),
        help_text=Help("Blabla"),
        custom_validate=(validators.LengthInRange(min_value=1),),
    )

rule_spec_foo = CheckParameters(
    name="foo",
    title=Title("My Foo"),
    topic=Topic.GENERAL,
    parameter_form=_parameter_form,
    condition=HostAndItemCondition(item_title=Title("My Foo"), item_form=_item_form),
)

When omit the item_form parameter, the error goes away.

Based on the API specification it should be possible to give both parameters:

class HostAndItemCondition(item_title, item_form=String(title=None, help_text=None, migrate=None, custom_validate=(<cmk.rulesets.v1.form_specs.validators.LengthInRange object>, ), label=None, macro_support=False, prefill=InputHint(value=''), field_size=<FieldSize.MEDIUM: 2>))

What am I doing wrong?

P.S.: @moritz Only with the full stack trace I could find the root cause of the error. I found the place in the checkmk source tree where this error is thrown. From the documentation and source code I could not find how to turn on the debug mode in UI job scheduler. Therefore I changed the logging like this:

daniel@myhost ~/src/checkmk (2.4.0)
$ git diff cmk/gui/utils/rule_specs/registering.py
diff --git a/cmk/gui/utils/rule_specs/registering.py b/cmk/gui/utils/rule_specs/registering.py
index 348d4d5d2..78151cf44 100644
--- a/cmk/gui/utils/rule_specs/registering.py
+++ b/cmk/gui/utils/rule_specs/registering.py
@@ -29,7 +29,7 @@ def register_plugin(loaded_rule_spec: LoadedRuleSpec) -> None:
     except Exception as e:
         if debug_enabled():
             raise e
-        logger.error(
+        logger.exception(
             "Error converting to legacy rulespec '%s' : %s", loaded_rule_spec.rule_spec.name, e
         )
         add_failed_plugin(

You are passing the callaback here: _item_form. I think you need to pass the instance:_item_form().
Passing the callback was needed in the old ValueSpecs, for performance reasons and to make localizations _("like this") work. Since we don’t have that restriction anymore, you can (as in “have to”) pass the instance in many places.

Just one addition regarding the debugging: We also have a script that will load and validate a lot of plugins. You best run it in a running site (there are some things we can only validate then). It will report various inconsistencies and also has a --debug flag that probably would have shown you the traceback:

OMD[mySite]:~$ cmk-validate-plugins --debug
Agent based plugins loading succeeded, Active checks loading succeeded, Special agents loading succeeded, Rule specs loading succeeded, Rule specs forms creation succeeded, Referenced rule specs validation succeeded, Loaded rule specs usage succeeded

2 Likes