Advanced search links on mailing reports page give "DB Error: syntax error"
After a mailing has been sent, all of the "Advanced Search" links on the mailing report page give a "DB Error: syntax error" page.
Steps to reproduce:
- create a new mailing
- wait for cron or execute the mailings scheduler job from /civicrm/admin/job
- go to /civicrm/mailing/browse/scheduled?reset=1&scheduled=true and click on the report link for the completed mailing
- click any of the "Advanced Search" links on the right side of the rows
Logs from ConfigAndLog show:
SELECT DISTINCT LEFT(contact_a.sort_name, 1) as sort_name
FROM civicrm_contact contact_a
LEFT JOIN civicrm_mailing_recipients ON civicrm_mailing_recipients.contact_id = contact_a.id
LEFT JOIN civicrm_mailing ON civicrm_mailing.id = civicrm_mailing_recipients.mailing_id
WHERE ( AND civicrm_mailing.id IN (15403) ) AND (contact_a.is_deleted = 0)
GROUP BY sort_name
ORDER BY sort_name asc
[nativecode=1064 ** You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'AND civicrm_mailing.id IN (15403) ) AND (contact_a.is_deleted = 0)
The error occurs in 5.21.2 (we are testing this in preparation for the next ESR release) and I am also able to reproduce the problem on https://dmaster.demo.civicrm.org. The error doesn't occur in 5.13.8.