I find that if I create a new tag via the api, and then try to attach it to a contact with the entity_tag api, it will sometimes fail with the message "'##' is not a valid option for field tag_id".

This is because the entity_tag api checks for the existence of the tag_id using a pseudoconstant lookup -- which is a cached value. How can I easily clear that pseudoconstant cache after the tag has been created to ensure it can be added to the entity?


You can manually clear caches with civicrm_api3('AnyEntity', 'getfields', array('cache_clear' => 1)); (use any valid entity, it doesn't matter which).

However, if you are using the api to create tags, and this does not automatically clear the cached list of tags, I would consider it a bug. If you are able to reproduce it in the latest version please look in the issue tracker for an open bug report, and if there isn't one, please open one.

  • This worked. We're running 4.4.x. I diffed the tag-related api files between 4.4 and 4.6 and don't see any changes that would suggest the tags cache is cleared or rebuilt after creation. – lcdservices Apr 20 '15 at 14:29

CRM_Core_PseudoConstant::flush() should do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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