CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API3 call loop {Tag-Create, EntityTag-Create} causes exception
Pages: [1]

Author Topic: API3 call loop {Tag-Create, EntityTag-Create} causes exception  (Read 630 times)

bsilvern

  • I’m new here
  • *
  • Posts: 14
  • Karma: 2
  • CiviCRM version: 4.6
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.37-0+wheezy1
  • PHP version: 5.4.4-14+deb7u10
API3 call loop {Tag-Create, EntityTag-Create} causes exception
March 05, 2015, 05:15:54 pm
I'm trying to apply a set of tags to a single contact using API3 but I'm getting an exception during the sequence of API calls.

The flow (which I refer to later as "test_ng") is:
loop (n=0..N) {
  tag_id = Tag-Create(tag_name[n]) //create a tag
  EntityTag-Create(tag_id) //assign the tag to a contact
}

What I found is that the first time through the loop all works well -- a tag is created and applied to a contact. But the second and all subsequent times through the loop on the EntityTag-Create call I get:
Quote
Caught exception: 'XXX' is not a valid option for field tag_id
where XXX is the tag_id.

I can see then that tag_name[0] and tag_name[1] are indeed created, but tag_name[1] does not get assigned to the contact.

Now here's the fun part. If I instead run the following (I'll call this test_ok):
loop (n=0..N) {
  tag_id[n] = Tag-Create(tag_name[n]) //create all the tags
}
loop (n=0..N) {
  EntityTag-Create(tag_id[n]) //assign all the tags
}
then everything works as expected.

And If I run
  test_ok();
  test_ng();
then test_ok passes and test_ng creates the exception during each iteration of its loop.

And If I run
  test_ng();
  test_ok();
then test_ng creates an exception on all but its first iteration and test_ok creates the exception on each iteration.

So it appears that the API becomes unhappy performing the sequence:
  EntityTag-Create
  Tag-Create
  EntityTag-Create //Exception!
and this makes all subsequent calls to EntityTag-Create cause an exception, apparently for the lifetime of the process.

I've attached a test script which demonstrates the problem. It produces the results shown below.

Problem was observed on CiviCRM 4.5.3 and 4.6.beta1.

I believe this is a bug. Any thoughts?


Test script output:
Code: [Select]
Deleting 10 Test tags.


************************************ test_ok ************************************
Creating tag TagTest_0.
Creating tag TagTest_1.
Creating tag TagTest_2.
Creating tag TagTest_3.
Creating tag TagTest_4.
Creating tagid 991 for Contact 3.
Creating tagid 992 for Contact 3.
Creating tagid 993 for Contact 3.
Creating tagid 994 for Contact 3.
Creating tagid 995 for Contact 3.

************************************ test_ng ************************************
Creating tag TagTest_5.
Creating tagid 996 for Contact 3.
Caught exception: '996' is not a valid option for field tag_id
Creating tag TagTest_6.
Creating tagid 997 for Contact 3.
Caught exception: '997' is not a valid option for field tag_id
Creating tag TagTest_7.
Creating tagid 998 for Contact 3.
Caught exception: '998' is not a valid option for field tag_id
Creating tag TagTest_8.
Creating tagid 999 for Contact 3.
Caught exception: '999' is not a valid option for field tag_id
Creating tag TagTest_9.
Creating tagid 1000 for Contact 3.
Caught exception: '1000' is not a valid option for field tag_id

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: API3 call loop {Tag-Create, EntityTag-Create} causes exception
March 05, 2015, 05:55:35 pm
Probably we need to ensure that the tag.create action clears the pseudoconstant cache.
Try asking your question on the new CiviCRM help site.

bsilvern

  • I’m new here
  • *
  • Posts: 14
  • Karma: 2
  • CiviCRM version: 4.6
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.37-0+wheezy1
  • PHP version: 5.4.4-14+deb7u10
Re: API3 call loop {Tag-Create, EntityTag-Create} causes exception
March 18, 2015, 05:53:23 pm
Created CRM-16139
https://issues.civicrm.org/jira/browse/CRM-16139

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: API3 call loop {Tag-Create, EntityTag-Create} causes exception
April 13, 2015, 03:04:44 am
heh! awesome - this cost me a couple of hours!!!

this fixed my problem:

    CRM_Core_PseudoConstant::flush();


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API3 call loop {Tag-Create, EntityTag-Create} causes exception

This forum was archived on 2017-11-26.