Skip to content

ParameterDefinitionModel

Bases: PumCustomBaseModel

ParameterDefinitionModel represents a parameter definition in the configuration.

Attributes:

Name Type Description
name str

Name of the parameter.

type ParameterType

Type of the parameter (default is TEXT).

default Any | None

Optional default value for the parameter.

description str | None

Optional description of the parameter.

app_only bool

If True, the parameter can be changed when recreating the app. Standard parameters (app_only=False) must remain the same across the whole module lifecycle.

Source code in pum/config_model.py
class ParameterDefinitionModel(PumCustomBaseModel):
    """ParameterDefinitionModel represents a parameter definition in the configuration.

    Attributes:
        name: Name of the parameter.
        type: Type of the parameter (default is TEXT).
        default: Optional default value for the parameter.
        description: Optional description of the parameter.
        app_only: If True, the parameter can be changed when recreating the app.
            Standard parameters (app_only=False) must remain the same across
            the whole module lifecycle.
    """

    name: str
    type: ParameterType = Field(default=ParameterType.TEXT, description="Type of the parameter")
    default: Any | None = None
    description: str | None = None
    values: list[Any] | None = Field(
        default=None, description="List of allowed values for this parameter."
    )
    app_only: bool = Field(
        default=False, description="If True, the parameter can be adapted when recreating the app."
    )

    @model_validator(mode="before")
    def validate_default(cls, values):
        if values.get("type") == ParameterType.BOOLEAN:
            values["default"] = values.get("default", False) in (1, "1", "true", "TRUE", True)
        return values

    @model_validator(mode="after")
    def validate_default_in_values(self):
        if self.values and self.default is not None and self.default not in self.values:
            raise ValueError(
                f"Parameter '{self.name}' has default '{self.default}' "
                f"which is not in the allowed values: {self.values}"
            )
        return self