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) »
  • Contributions created with 4.2 API give fatal error on edit
Pages: 1 [2]

Author Topic: Contributions created with 4.2 API give fatal error on edit  (Read 4693 times)

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: Contributions created with 4.2 API give fatal error on edit
September 23, 2012, 11:09:15 am
Wait, what? Are you saying that update is not a valid action for contributions in the API? But that the API can update contributions by using the create action and supplying a contribution ID?
Using create to do an update seems... not intuitive. Is that documented? Is that the case for other entity types as well as contributions, and if so, which ones? Is there a reason for that? ???

Also, shooting Xavier seems a bit harsh...

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Contributions created with 4.2 API give fatal error on edit
September 23, 2012, 12:07:12 pm
Yes, that's right - UPDATE is RUBBISH. It does a GET + a CREATE with the variables from the GET. When we first brought in apiv3 there were a lot of cases where variables were required that shouldn't have been. But those problems are fixed now

Shooting X seems entirely reasonable to me.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: Contributions created with 4.2 API give fatal error on edit
September 23, 2012, 12:15:42 pm
Oh, I didn't know that. OK, so I want to be sure I understand you clearly: You're saying that if we want to update an entity using the API, then we should always use the create action and supply the id of the entity to be updated, rather than using the update action? And this works for all entity types? Does this mean that the update action is completely redundant now?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Contributions created with 4.2 API give fatal error on edit
September 23, 2012, 12:35:15 pm
We would remove the update action - but it might break people's code if we do - so it's still there - but I hope to remove it from the api explorer
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: Contributions created with 4.2 API give fatal error on edit
September 23, 2012, 12:36:19 pm
OK, thanks for your help. I'll update my code accordingly.

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: Contributions created with 4.2 API give fatal error on edit
September 24, 2012, 03:30:23 am
OK, so I tried updating OptionValue records using the API create action instead of the update action as per Eileen's advice above, and it went all sorts of wrong.

Firstly I got a fatal error because it was expecting the option_group_id field to be passed. (All an update should require is the ID of the entity to be updated, right?)

Then when I supplied the option_group_id, API create altered the values of several fields that I didn't supply. Specifically, it reset the is_default and is_active fields to their default values, and it set the value and weight fields to the next values in the sequence. It seems to me that an update should not change the values of fields you aren't updating.

So I'm not sure I trust the recommendation to use API create instead of API update. It doesn't seem safe to me. Can anyone comment?
« Last Edit: September 24, 2012, 04:16:44 am by kirk »

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Contributions created with 4.2 API give fatal error on edit
September 25, 2012, 01:34:51 pm
Can you log a ticket in JIRA about the option value API - that's a bug.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: Contributions created with 4.2 API give fatal error on edit
September 26, 2012, 01:57:56 am
OK, I've created a ticket: CRM-10921.

bartclarkson

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.2
  • CMS version: Drupal 7
  • MySQL version: 5.x
  • PHP version: 5.x
Re: Contributions created with 4.2 API give fatal error on edit
October 03, 2012, 12:35:01 pm
It would appear this affects CRM_Contribute_Form_Task_PDFLetterCommon.  I replaced the update with create (update was causing the automatic Receipt & Thank You date updates to fail).  I will add a ticket to JIRA.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Contributions created with 4.2 API give fatal error on edit
October 03, 2012, 02:29:29 pm
Bart's issue was a bit different and was fixed in the 4.2.2 release - http://issues.civicrm.org/jira/browse/CRM-9998?page=com.atlassian.jirafisheyeplugin:fisheye-issuepanel
Protect your investment in CiviCRM by  becoming a Member!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Contributions created with 4.2 API give fatal error on edit
March 17, 2013, 11:36:29 pm
Sorry to resurrect an old thread, but given that it was discussing my own death, felt entitled.

http://issues.civicrm.org/jira/browse/CRM-12140

Got one other issue in the pull request then I'll push this one next.

I would take the time to somewhat thanks kirk to have dared telling Eileen that her idea of shooting me was "a bit harsh". That's good to have support when you need it ;)

For the record, there is a least one other dissident opinion on that topic among the api folks, and I don't quite agree that shooting me is entirely reasonable (no matter the api issue at hand).
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: Contributions created with 4.2 API give fatal error on edit
March 18, 2013, 09:44:22 am
Hi Xavier, good to see you've avoided the firing squad so far.  ;)

Since I last posted on this thread I've done a lot of work using the API and found that as it stands, the create action is definitely not fit to take over from the update action, and unless a fair amount of work is done to make it fit, I believe it would be premature to retire the update action.

For more details, see the issue I've just logged: CRM-12144.

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: Contributions created with 4.2 API give fatal error on edit
March 18, 2013, 10:02:41 am
Beyond making bug reports I don't have the time to help develop the API at the moment, and while I don't know the API as well as the developers, I have used it a lot in the course of developing a CiviCRM system for my organisation, so for what it's worth, here are my feelings on this issue:

I appreciate Eileen's point that it should not be necessary to do a database query every time you do an update, as the API update action does. That is inefficient. However, from a user's point of view, it's just not intuitive to use a function called 'create' to perform an update. Perhaps instead of scrapping the update action, it could be rewritten to do what create currently does when you call it with an id? (Minus the bugs of course.)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Contributions created with 4.2 API give fatal error on edit
March 21, 2013, 07:06:32 am
kirk, very good points that have generated a fair bit of discussion.

At the end, coleman has THE answer: the action should be "save", not create nor update nor...

Not 100% sure how we will proceed to go there...

As for update = create with id, that was what we tried, but it seems to break too many things so we had to revert.

We all agree it's needed to get these bugs ironed out so you can use create+id and a single field and it shouldn't modify any of the others, but we currently lack the resources and time to make it happen and would really appreciate any extra help that could contribute...

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Contributions created with 4.2 API give fatal error on edit
March 21, 2013, 02:41:07 pm
NB - I think the main help that is useful would be unit tests. In most cases fixing a particular case where create alters a field is not the problem - it's ensuring the change is 'locked in' with a unit test.

The sort of manual testing & reporting that Kirk has done is also useful & I would encourage people to update

http://issues.civicrm.org/jira/browse/CRM-12144

with any more cases where create alters fields it shouldn't
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Contributions created with 4.2 API give fatal error on edit

This forum was archived on 2017-11-26.