Answers.Body: <p>I was not aware that the system had been patched with <a href="https://github.com/civicrm/civicrm-core/pull/10844/files" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/pull/10844/files</a>. Reversing the patch resolved the problem.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-31T10:44:55.823Z
Answers.Text: alternative at https://github.com/civicrm/civicrm-core/pull/11614
Answers.UserDisplayName: user4278
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-15T09:42:00.253Z
Answers.LastActivityDate: 2017-12-15T09:42:00.253Z
Answers.UserDisplayName: michaelmcandrew
Body: <p>This behaviour happens on a certain environment, but not on another. I am trying to work out why.</p>
  
  <p>There is <a href="https://github.com/civicrm/civicrm-core/blob/4.7.27/CRM/Mailing/BAO/MailingJob.php#L550" rel="nofollow noreferrer">a while loop in CRM_Mailing_BAO_MailingJob::deliver()</a> that cycles through emails to be delivered.</p>
  
  <p>I noticed that the loop was ending prematurely. I tracked this down to some custom code I had addes that was adding a token. In this code, I was calling MailingJob.getsingle.</p>
  
  <p>It turns out that many calls to the API and it seems other methods too will cause the loop to end prematurely.</p>
  
  <p>The simplest proof of concept I came up with was</p>
  
  <pre><code>var_dump($eq-&gt;N);
  while ($eq-&gt;fetch()) {
    civicrm_api3('Contact', 'get');
    var_dump($eq-&gt;N);
    var_dump($eq-&gt;fetch());exit;
  </code></pre>
  
  <p>which outputs</p>
  
  <pre><code>int(50)
  int(50)
  bool(false)
  </code></pre>
  
  <p>which is madness, I am sure you will agree.</p>
  
  <p>Do you have any ideas what is going on here?</p>
  
Tags: <developer>
Title: Is the free() method being called inadvertently on my DataObject?
ThreadText: # Is the free() method being called inadvertently on my DataObject?
  
  (Asked by: username_0 on 2017-12-14)
  
  This behaviour happens on a certain environment, but not on another. I am trying to work out why.
  There is a while loop in CRM_Mailing_BAO_MailingJob::deliver() that cycles through emails to be delivered.
  I noticed that the loop was ending prematurely. I tracked this down to some custom code I had addes that was adding a token. In this code, I was calling MailingJob.getsingle.
  It turns out that many calls to the API and it seems other methods too will cause the loop to end prematurely.
  The simplest proof of concept I came up with was
  var_dump($eq->N);
  while ($eq->fetch()) {
    civicrm_api3('Contact', 'get');
    var_dump($eq->N);
    var_dump($eq->fetch());exit;
  
  which outputs
  int(50)
  int(50)
  bool(false)
  
  which is madness, I am sure you will agree.
  Do you have any ideas what is going on here?
  
  **Tags:** developer
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-12-15. Score: 1
  
  I was not aware that the system had been patched with <https://github.com/civicrm/civicrm-core/pull/10844/files>. Reversing the patch resolved the problem.
  
  > **Comments:**
  > **username_1**: alternative at https://github.com/civicrm/civicrm-core/pull/11614  
  
  ---
  
  