When we clone our production instance to staging, we restore the database with updated host information prior to restoring the database.

Querying a smart group returns all contacts in database, not just those in the smart group. Running the Rebuild Smart Group Cache scheduled job does not do anything.

Here Eileen says How do the Rebuild Smart Group Cache scheduled job and the Smart group cache timeout setting interact?

Note I DO recommend running the job that flushes expired groups by scheduled job - just not the one that rebuild them all, even the ones you don't really need

Where is that job?

2 Answers 2


We encountered the same problem. Whenever cloning the system (CiviCRM 5.65.1) from production to staging, all smart groups were non-functional. Instead, all contacts became members of all smart groups.

The Drupal protocol showed this warning:

Warning: Invalid argument supplied for foreach() in CRM_Contact_BAO_SavedSearch::getFormValues() (line 65 of /xxx/crm.mysite.de/httpdocs/dev/public/sites/all/modules/civicrm/CRM/Contact/BAO/SavedSearch.php).

I found out the reason for this:

When we clone the production system to staging, we create a dump of the CiviCRM database with mysqldump and then replace every instance of the production URL with the staging URL in this database dump (using sed). This works fine for most tables, but in the table civicrm_saved_search there is a column form_values that stores the SQL call on which a saved search is based on. (The smart groups are based on these saved searches then.) This column form_values contains data in the form of a serialized string, for example:


When sed now replaces https://crm.mysite.de with https://crmtest.mysite.de, the format of the serialized string is destroyed, because the value s:86 in front of the URL describes the number of characters in the following string, which is not correct anymore after replacing the URL (86 with crm.mysite.de, but 90 with crmtest.mysite.de).

So if in this example you replace not only the production URL with the staging URL, but also the number of characters of the production URL (complete, with directories) with the number of characters of the staging URL, the smart group is functional again! :) Don't forget to empty the CiviCRM cache before checking if the smart groups are functional again.

I consider it not best practise though that the CiviCRM code responsable for unserializing this field (public/sites/all/modules/civicrm/CRM/Contact/BAO/SavedSearch.php, line 61) does not check if the unserialize function really returns an array, or just FALSE. It just hands over any result to the rest of the function.


I don't see any such job, nor do I recall such a thing.

But: the contacts that are in smart groups are cached in civicrm_group_contact_cache so you should be able to clear that using the CiviCRM "cleanup caches" option (under Administer -> System settings).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.