Mailing Error when civicrm_mailing_group has duplicate entries of recipient groups
I see a number of entries in
civicrm_mailing_group with same entity_id, entity_table, group_type and mailing_id values.
I think this should've been avoided by civi by making this combination of field as unique keys?
If not - re-using such mailings can lead to an error when group_concat exceeds its maximum length of holding the value of group ids at https://github.com/civicrm/civicrm-core/blob/master/CRM/Mailing/BAO/Mailing.php#L123
$dao = CRM_Utils_SQL_Select::from('civicrm_mailing_group') ->select('GROUP_CONCAT(entity_id SEPARATOR ",") as group_ids, group_type, entity_table') ->where('mailing_id = #mailing_id AND entity_table RLIKE "^civicrm_(group.*|mailing)$" ') ->groupBy(['group_type', 'entity_table']) ->param('!groupTableName', CRM_Contact_BAO_Group::getTableName()) ->param('#mailing_id', $mailingID) ->execute();
Default max length is 1024 which leads to the following error if number of characters are more.
Maybe, we just need to use DISTINCT in the above query? I'll create a PR for it soon.