#16064·chatwoot

Automation: attribute_changed condition treats lowercase AND (as sent by the dashboard) as OR

Author: AsifMahsudCreated Sep 29, 2026Updated Sep 29, 2026

Describe the bug

An automation rule that combines an attribute changed condition with another condition using AND behaves as OR when the rule was saved from the dashboard.

The dashboard sends query_operator in lowercase ('and' / 'or', see app/javascript/dashboard/constants/automation.js and composables/useEditableAutomation.js), and AutomationRule#validate_single_condition accepts either case because it upcases before checking. The SQL branch is fine with that because SQL keywords are case-insensitive. But the Ruby branch for attribute-changed conditions compares the raw string:

https://github.com/chatwoot/chatwoot/blob/d4b54412a87d6ab42929d03c0dbc291f8e73270b/app/services/automation_rules/conditions_filter_service.rb#L102-L109

filter['query_operator'] == 'AND' is false for 'and', so the method falls into the else branch and unions the records instead of intersecting them. Every attribute-changed rule created through the UI with AND therefore fires whenever either side matches.

To Reproduce

  1. Settings → Automations → add a rule on Conversation Updated.
  2. Condition 1: Company name attribute changed from DC to Marvel, joined with AND.
  3. Condition 2: Status equal to Snoozed.
  4. Action: assign to a team.
  5. Take an open conversation whose contact company name changes from DC to Marvel.

Actual: the rule fires and the team is assigned although the status condition is not met.

Expected: the rule does not fire; it should only fire when both conditions hold.

The existing specs only exercise uppercase 'AND' / 'OR' (spec/listeners/automation_rule_listener_old_spec.rb), which is why this passes CI. A spec with 'and' reproduces it:

ruby
rule.update!(conditions: [
  { values: { from: ['DC'], to: ['Marvel'] }, attribute_key: 'company_name', query_operator: 'and', filter_operator: 'attribute_changed' },
  { values: ['snoozed'], attribute_key: 'status', query_operator: nil, filter_operator: 'equal_to' }
])
conversation.update!(status: :open)
AutomationRules::ConditionsFilterService.new(rule, conversation, changed_attributes: { company_name: %w[DC Marvel] }).perform
# => true on develop, expected false

Expected behavior

attribute_changed_filter_query should treat the query operator case-insensitively, the same way the model validation does, so 'and' intersects and 'or' unions.

I have a one-line fix plus specs ready and will open a PR.

Environment

Self-hosted (also reproducible on current develop, d4b5441)

Cloud Provider

No response

Platform

Docker

Operating system

Linux

Browser and version

Not browser-specific

Docker (if applicable)

chatwoot/chatwoot:v4.18.0

Additional context

The bug only affects attribute-changed conditions; other condition types are combined in SQL where and/or are case-insensitive.