Conditions¶
Conditions control when a rule executes. They can be attached to field conversions
($convert), date formatting ($format_date), and skip rules ($skip).
All conditions in a rule must evaluate to True for the rule to execute.
Condition Format¶
Conditions are specified as a dict where each key is a condition name and the value is the argument for that condition:
{
"$convert_example": {
"fieldname": "status",
"conditions": {
"is_null": False,
"equals": "active",
},
"actions": [...]
}
}
In the example above, both is_null: False (field is not null) and equals: "active"
must be true for the actions to run.
Skip Rules¶
The $skip rule uses conditions to skip the entire record:
{
"$skip": {
"fieldname": "status",
"condition": {
"equals": "deleted",
}
}
}
When the condition evaluates to True, the record is skipped and the convertor
returns the DEFAULT_VALUE (empty dict by default).
Condition Reference¶
String Type Checks¶
is_a_stringReturns
Trueif the field value is a string.{"conditions": {"is_a_string": True}}
is_not_a_stringReturns
Trueif the field value is not a string.{"conditions": {"is_not_a_string": True}}
Null Checks¶
is_nullChecks whether the field value is
None. PassTrueto match null values,Falseto match non-null values.{"conditions": {"is_null": False}} # field must not be None {"conditions": {"is_null": True}} # field must be None
field_does_existReturns
Trueif the field value is notNone.{"conditions": {"field_does_exist": True}}
field_does_not_existReturns
Trueif the field value isNone.{"conditions": {"field_does_not_exist": True}}
Equality Checks¶
equalsReturns
Trueif the field value equals the specified value.{"conditions": {"equals": "active"}}
does_not_equalReturns
Trueif the field value does not equal the specified value.{"conditions": {"does_not_equal": "deleted"}}
List Membership¶
in_listReturns
Trueif the field value is in the provided list.{"conditions": {"in_list": ["active", "pending"]}}
not_in_listReturns
Trueif the field value is not in the provided list.{"conditions": {"not_in_list": ["deleted", "archived"]}}
String Content¶
containsReturns
Trueif the field value contains the specified substring.{"conditions": {"contains": "http"}}
does_not_containReturns
Trueif the field value does not contain the specified substring.{"conditions": {"does_not_contain": "spam"}}
str_lengthReturns
Trueif the string length equals the specified value.{"conditions": {"str_length": 2}}
Date Checks¶
date_not_todayReturns
Trueif the field value (aYYYY-MM-DDdate string) is not today’s date.{"conditions": {"date_not_today": True}}
Combining Conditions¶
Multiple conditions can be combined in a single dict. All conditions must pass:
{
"$convert_example": {
"fieldname": "email",
"conditions": {
"is_null": False,
"contains": "@",
"does_not_contain": "test",
},
"actions": [
{"action_type": "to_lower_str", "action_value": "email"}
]
}
}