Answers.Body: <p>In your second example, the error is arising during a 'rebuildMenuandCaches' phase of the extension disable process and is an issue when it's reconciling an option group. I'd suspect a bad extension (probably not cividiscount), which you could fix by using the database extension table to just disable them all (set the is_active field to 0), clear caches and then try re-enabling one by one.</p>
  <p>It wouldn't surprise me if this is php-related.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-03T14:51:58.163Z
Answers.LastActivityDate: 2024-04-03T14:51:58.163Z
Answers.UserDisplayName: Alan Dixon
Body: <p>I need help figuring out what's causing an error in CiviCRM and how to fix it.  It happens when trying to install or uninstall new civi extensions (both from UI and CLI), when trying to rebuild the menus, when clearing the cache from Civi UI.</p>
  <p>Thanks for any assistance.</p>
  <h2>Currently running:</h2>
  <p>Drupal Version 10.2.4, PHP Version 8.3.2, CiviCRM Version 5.71.2</p>
  <h2>Example 1</h2>
  <p>Call to:  <a href="https://www.XXXXXXXX.org/civicrm/admin/setting/updateConfigBackend?reset=1" rel="nofollow noreferrer">https://www.XXXXXXXX.org/civicrm/admin/setting/updateConfigBackend?reset=1</a></p>
  <pre><code>    $Fatal Error Details = array:3 [ &quot;message&quot; =&gt; &quot; is not of type String&quot; &quot;code&quot; =&gt; null &quot;exception&quot; =&gt; CRM_Core_Exception {#22699 #message: &quot; is not of type String&quot; #code: 0 #file: &quot;/home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php&quot; #line: 1898 #cause: null -_trace: null -errorData: array:1 [ &quot;error_code&quot; =&gt; 0 ] trace: { 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php:1898 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php:1830 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Reference/Dynamic.php:104 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php:2681 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/Api4/Utils/CoreUtil.php:326 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php:379 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php:180 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php:115 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:421 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/Api4/Action/System/Flush.php:40 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/Api4/Provider/ActionObjectProvider.php:70 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/API/Kernel.php:156 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/Api4/Generic/AbstractAction.php:256 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Admin/Form/Setting/UpdateConfigBackend.php:48 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Form.php:641 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/StateMachine.php:144 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/QuickForm/Action/Next.php:43 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-packages/HTML/QuickForm/Controller.php:203 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-packages/HTML/QuickForm/Page.php:103 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Controller.php:355 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Utils/Wrapper.php:98 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:293 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:69 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:36 { …} 
  /home/XXXXXXXX/www/www/web/modules/contrib/civicrm/src/Civicrm.php:88 { Drupal\civicrm\Civicrm-&gt;invoke($args) › ob_start(); › $content = \CRM_Core_Invoke::invoke($args); › $output = ob_get_clean(); arguments: { $args: array:4 [ …4] } } 
  /home/XXXXXXXX/www/www/web/modules/contrib/civicrm/src/Controller/CivicrmController.php:83 { …} Drupal\civicrm\Controller\CivicrmController-&gt;main() {} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/Render/Renderer.php:627 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:121 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:97 { …}
  /home/XXXXXXXX/www/www/vendor/symfony/http-kernel/HttpKernel.php:181 { …} 
  /home/XXXXXXXX/www/www/vendor/symfony/http-kernel/HttpKernel.php:76 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/Session.php:58 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php:48 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php:28 { …} 
  /home/XXXXXXXX/www/www/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php:32 { …} 
  /home/XXXXXXXX/www/www/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:106 { …} 
  /home/XXXXXXXX/www/www/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:85 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php:48 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php:51 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php:36 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php:51 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/DrupalKernel.php:704 { …} 
  /home/XXXXXXXX/www/www/web/index.php:19 { …} } } ]
  </code></pre>
  <h2>Example 2</h2>
  <p>CLI from SSH to uninstall civi extension no longer needed:
  composer exec cv ext:uninstall org.civicrm.module.cividiscount</p>
  <pre><code>Error: API Call Failed: Array
  (
      [entity] =&gt; Extension
      [action] =&gt; disable
      [params] =&gt; Array
          (
              [keys] =&gt; Array
                  (
                      [0] =&gt; org.civicrm.module.cividiscount
                  )
  
              [debug] =&gt; 1
              [version] =&gt; 3
          )
  
      [result] =&gt; Array
          (
              [error_code] =&gt; 0
              [entity] =&gt; Extension
              [action] =&gt; disable
              [trace] =&gt; #0 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php(1830): CRM_Core_DAO::composeQuery('SELECT count(id...', Array, true)
  #1 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Reference/Dynamic.php(104): CRM_Core_DAO::singleValueQuery('SELECT count(id...', Array)
  #2 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php(2681): CRM_Core_Reference_Dynamic-&gt;getReferenceCount(Object(CRM_Core_DAO_OptionValue))
  #3 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/Api4/Utils/CoreUtil.php(326): CRM_Core_DAO-&gt;getReferenceCounts()
  #4 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php(379): Civi\Api4\Utils\CoreUtil::getRefCount('OptionValue', NULL)
  #5 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php(180): CRM_Core_ManagedEntities-&gt;removeStaleEntity(Array)
  #6 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php(115): CRM_Core_ManagedEntities-&gt;reconcileEntities(Array)
  #7 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(421): CRM_Core_ManagedEntities-&gt;reconcile()
  #8 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Extension/Manager.php(439): CRM_Core_Invoke::rebuildMenuAndCaches(true)
  #9 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/api/v3/Extension.php(150): CRM_Extension_Manager-&gt;disable(Array)
  #10 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_extension_disable(Array)
  #11 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(156): Civi\API\Provider\MagicFunctionProvider-&gt;invoke(Array)
  #12 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(79): Civi\API\Kernel-&gt;runRequest(Array)
  #13 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/api/api.php(28): Civi\API\Kernel-&gt;runSafe('Extension', 'disable', Array)
  #14 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/src/Command/BaseCommand.php(39): civicrm_api('Extension', 'disable', Array)
  #15 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/src/Command/ExtensionUninstallCommand.php(44): Civi\Cv\Command\BaseCommand-&gt;callApiSuccess(Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput), 'Extension', 'disable', Array)
  #16 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/vendor/symfony/console/Command/Command.php(127): Civi\Cv\Command\ExtensionUninstallCommand-&gt;execute(Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput))
  #17 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/vendor/symfony/console/Application.php(637): Cvphar\Symfony\Component\Console\Command\Command-&gt;run(Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput))
  #18 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/vendor/symfony/console/Application.php(190): Cvphar\Symfony\Component\Console\Application-&gt;doRunCommand(Object(Civi\Cv\Command\ExtensionUninstallCommand), Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput))
  #19 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/src/Application.php(67): Cvphar\Symfony\Component\Console\Application-&gt;doRun(Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput))
  #20 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/vendor/symfony/console/Application.php(101): Civi\Cv\Application-&gt;doRun(Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput))
  #21 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/src/Application.php(33): Cvphar\Symfony\Component\Console\Application-&gt;run()
  #22 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/bin/cv(28): Civi\Cv\Application::main('phar:///home/th...')
  #23 /home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar(14): require('phar:///home/th...')
  #24 /home/XXXXXXX/www/www/vendor/civicrm/cli-tools/bin/cv(7): require('/home/thinkfirs...')
  #25 /home/XXXXXXX/www/www/vendor/bin/cv(119): include('/home/thinkfirs...')
  #26 {main}
              [is_error] =&gt; 1
              [error_message] =&gt;  is not of type String
          )
  
  )
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-03T23:27:16.447Z
Comments.Text: Encountered a similar problem on 5.72-rc when flushing (`cv flush`) a local dev-site. Observed with php-cli@8.2 or 7.4. Don't have cividiscount. Problem occurred while it was checking refcount  for `civicrm_acl where entity_id=%1...` with [1=>[NULL, 'String']. (Accidentally lost the config, and having trouble reproducing again.)
Comments.UserDisplayName: Tim Otten
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-26T09:17:26.347Z
Comments.Text: I had a similar problem on CiviCRM 5.72.2: It came out that it was caused by the AdminUI extension. It is the system of one of our clients, but probably we will be able to reproduce it.
Comments.UserDisplayName: Detlev Sieber
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-02T12:08:01.660Z
Comments.Text: I've hit this too. When debugging the first error was with the civicrm_admin_ui extension, so I disabled it. Then it was hit with the civigrant extension (which we don't have enabled, but because that's recently moved to an extension I think it's trying to cleanup the managed entities). It's triggered by the CRM_Core_ManagedEntitites::removeStaleEntity() method. So I think this is definitely an issue in core. The actual location of the error is the singleValueQuery() call in CRM_Core_Reference_Dynmaic::getReferenceCount().
Comments.UserDisplayName: lcdservices
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-02T12:26:20.373Z
Comments.Text: Edit to my previous comment -- the civigrant extension did not pose a problem. Just the admin_ui.
Comments.UserDisplayName: lcdservices
Tags: <drupal><api><error>
Title: CiviCRM fatal error API 'is not of type String'
ThreadText: # CiviCRM fatal error API 'is not of type String'
  
  (Asked by: username_0 on 2024-04-02)
  
  I need help figuring out what's causing an error in CiviCRM and how to fix it. It happens when trying to install or uninstall new civi extensions (both from UI and CLI), when trying to rebuild the menus, when clearing the cache from Civi UI.
  
  Thanks for any assistance.
  
  ## Currently running:
  
  Drupal Version 10.2.4, PHP Version 8.3.2, CiviCRM Version 5.71.2
  
  ## Example 1
  
  Call to: <https://www.XXXXXXXX.org/civicrm/admin/setting/updateConfigBackend?reset=1>
  
  ```
      $Fatal Error Details = array:3 [ "message" => " is not of type String" "code" => null "exception" => CRM_Core_Exception {#22699 #message: " is not of type String" #code: 0 #file: "/home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php" #line: 1898 #cause: null -_trace: null -errorData: array:1 [ "error_code" => 0 ] trace: { 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php:1898 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php:1830 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Reference/Dynamic.php:104 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php:2681 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/Api4/Utils/CoreUtil.php:326 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php:379 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php:180 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php:115 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:421 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/Api4/Action/System/Flush.php:40 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/Api4/Provider/ActionObjectProvider.php:70 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/API/Kernel.php:156 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/Api4/Generic/AbstractAction.php:256 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Admin/Form/Setting/UpdateConfigBackend.php:48 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Form.php:641 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/StateMachine.php:144 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/QuickForm/Action/Next.php:43 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-packages/HTML/QuickForm/Controller.php:203 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-packages/HTML/QuickForm/Page.php:103 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Controller.php:355 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Utils/Wrapper.php:98 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:293 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:69 { …} 
  /home/XXXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:36 { …} 
  /home/XXXXXXXX/www/www/web/modules/contrib/civicrm/src/Civicrm.php:88 { Drupal\civicrm\Civicrm->invoke($args) › ob_start(); › $content = \CRM_Core_Invoke::invoke($args); › $output = ob_get_clean(); arguments: { $args: array:4 [ …4] } } 
  /home/XXXXXXXX/www/www/web/modules/contrib/civicrm/src/Controller/CivicrmController.php:83 { …} Drupal\civicrm\Controller\CivicrmController->main() {} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/Render/Renderer.php:627 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:121 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:97 { …}
  /home/XXXXXXXX/www/www/vendor/symfony/http-kernel/HttpKernel.php:181 { …} 
  /home/XXXXXXXX/www/www/vendor/symfony/http-kernel/HttpKernel.php:76 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/Session.php:58 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php:48 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php:28 { …} 
  /home/XXXXXXXX/www/www/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php:32 { …} 
  /home/XXXXXXXX/www/www/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:106 { …} 
  /home/XXXXXXXX/www/www/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:85 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php:48 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php:51 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php:36 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php:51 { …} 
  /home/XXXXXXXX/www/www/web/core/lib/Drupal/Core/DrupalKernel.php:704 { …} 
  /home/XXXXXXXX/www/www/web/index.php:19 { …} } } ]
  
  ```
  
  ## Example 2
  
  CLI from SSH to uninstall civi extension no longer needed:
  composer exec cv ext:uninstall org.civicrm.module.cividiscount
  
  ```
  Error: API Call Failed: Array
  (
      [entity] => Extension
      [action] => disable
      [params] => Array
          (
              [keys] => Array
                  (
                      [0] => org.civicrm.module.cividiscount
                  )
  
              [debug] => 1
              [version] => 3
          )
  
      [result] => Array
          (
              [error_code] => 0
              [entity] => Extension
              [action] => disable
              [trace] => #0 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php(1830): CRM_Core_DAO::composeQuery('SELECT count(id...', Array, true)
  #1 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Reference/Dynamic.php(104): CRM_Core_DAO::singleValueQuery('SELECT count(id...', Array)
  #2 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/DAO.php(2681): CRM_Core_Reference_Dynamic->getReferenceCount(Object(CRM_Core_DAO_OptionValue))
  #3 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/Api4/Utils/CoreUtil.php(326): CRM_Core_DAO->getReferenceCounts()
  #4 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php(379): Civi\Api4\Utils\CoreUtil::getRefCount('OptionValue', NULL)
  #5 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php(180): CRM_Core_ManagedEntities->removeStaleEntity(Array)
  #6 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/ManagedEntities.php(115): CRM_Core_ManagedEntities->reconcileEntities(Array)
  #7 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(421): CRM_Core_ManagedEntities->reconcile()
  #8 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/CRM/Extension/Manager.php(439): CRM_Core_Invoke::rebuildMenuAndCaches(true)
  #9 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/api/v3/Extension.php(150): CRM_Extension_Manager->disable(Array)
  #10 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_extension_disable(Array)
  #11 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(156): Civi\API\Provider\MagicFunctionProvider->invoke(Array)
  #12 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(79): Civi\API\Kernel->runRequest(Array)
  #13 /home/XXXXXXX/www/www/vendor/civicrm/civicrm-core/api/api.php(28): Civi\API\Kernel->runSafe('Extension', 'disable', Array)
  #14 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/src/Command/BaseCommand.php(39): civicrm_api('Extension', 'disable', Array)
  #15 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/src/Command/ExtensionUninstallCommand.php(44): Civi\Cv\Command\BaseCommand->callApiSuccess(Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput), 'Extension', 'disable', Array)
  #16 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/vendor/symfony/console/Command/Command.php(127): Civi\Cv\Command\ExtensionUninstallCommand->execute(Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput))
  #17 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/vendor/symfony/console/Application.php(637): Cvphar\Symfony\Component\Console\Command\Command->run(Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput))
  #18 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/vendor/symfony/console/Application.php(190): Cvphar\Symfony\Component\Console\Application->doRunCommand(Object(Civi\Cv\Command\ExtensionUninstallCommand), Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput))
  #19 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/src/Application.php(67): Cvphar\Symfony\Component\Console\Application->doRun(Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput))
  #20 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/vendor/symfony/console/Application.php(101): Civi\Cv\Application->doRun(Object(Cvphar\Symfony\Component\Console\Input\ArgvInput), Object(Cvphar\Symfony\Component\Console\Output\ConsoleOutput))
  #21 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/src/Application.php(33): Cvphar\Symfony\Component\Console\Application->run()
  #22 phar:///home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar/bin/cv(28): Civi\Cv\Application::main('phar:///home/th...')
  #23 /home/XXXXXXX/www/www/vendor/civicrm/cli-tools/extern/cv.phar(14): require('phar:///home/th...')
  #24 /home/XXXXXXX/www/www/vendor/civicrm/cli-tools/bin/cv(7): require('/home/thinkfirs...')
  #25 /home/XXXXXXX/www/www/vendor/bin/cv(119): include('/home/thinkfirs...')
  #26 {main}
              [is_error] => 1
              [error_message] =>  is not of type String
          )
  
  )
  
  ```
  
  **Tags:** drupal, api, error
  
  > **Comments:**
  > **username_1**: Encountered a similar problem on 5.72-rc when flushing (`cv flush`) a local dev-site. Observed with php-cli@8.2 or 7.4. Don't have cividiscount. Problem occurred while it was checking refcount  for `civicrm_acl where entity_id=%1...` with [1=>[NULL, 'String']. (Accidentally lost the config, and having trouble reproducing again.)  
  > **username_2**: I had a similar problem on CiviCRM 5.72.2: It came out that it was caused by the AdminUI extension. It is the system of one of our clients, but probably we username_0 be able to reproduce it.  
  > **username_3**: I've hit this too. When debugging the first error was with the civicrm_admin_ui extension, so I disabled it. Then it was hit with the civigrant extension (which we don't have enabled, but because that's recently moved to an extension I think it's trying to cleanup the managed entities). It's triggered by the CRM_Core_ManagedEntitites::removeStaleEntity() method. So I think this is definitely an issue in core. The actual location of the error is the singleValueQuery() call in CRM_Core_Reference_Dynmaic::getReferenceCount().  
  > **username_3**: Edit to my previous comment -- the civigrant extension did not pose a problem. Just the admin_ui.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_4 on 2024-04-03. Score: 2
  
  In your second example, the error is arising during a 'rebuildMenuandCaches' phase of the extension disable process and is an issue when it's reconciling an option group. I'd suspect a bad extension (probably not cividiscount), which you could fix by using the database extension table to just disable them all (set the is\_active field to 0), clear caches and then try re-enabling one by one.
  
  It wouldn't surprise me if this is php-related.
  
  
  ---
  
  