AssertionError: assert(is_string($field)) in assert()

Created on 25 March 2025, 3 months ago

Problem/Motivation

I have created a new Drupal 11 site, then followed the instructions at https://www.drupal.org/node/2716391#example-conditions , and after saving a test at step 6 of Quickstart instructions, I got

The website encountered an unexpected error. Try again later.

AssertionError: assert(is_string($field)) in assert() (line 330 of core/lib/Drupal/Core/Database/Query/Merge.php).
Drupal\Core\Database\Query\Merge->key(Array) (Line: 450)
Drupal\abjs\Form\AbjsTestForm->saveTest(Array, Object)
call_user_func_array(Array, Array) (Line: 105)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 43)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('abjs_test', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 593)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

See above

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇨🇦Canada alberto56

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @alberto56
  • 🇨🇦Canada alberto56

    It seems that line 330 of core/lib/Drupal/Core/Database/Query/Merge.php has this code:

    
      /**
       * Sets a single key field to be used as condition for this query.
       *
       * Same as \Drupal\Core\Database\Query\Merge::keys() but offering a signature
       * that is more natural for the case of a single key.        
       *
       * @param string $field
       *   The name of the field to set.                     
       * @param mixed $value
       *   The value to set into the database.                            
       *
       * @return $this
       *                                                        
       * @see \Drupal\Core\Database\Query\Merge::keys()
       */                                                    
      public function key($field, $value = NULL) {
        assert(is_string($field));          
        $this->keys([$field => $value]);
        return $this;                                                          
      }                                                             
    
    

    But line 450 of src/Form/AbjsTestForm.php has the following code:

            $this->database->merge('abjs_test_condition')
              ->key(['tid' => $tid, 'cid' => $cid])
              ->fields(['tid' => $tid, 'cid' => $cid])->execute();
    

    In other words, AbjsTestForm. is passing an array [tid=>tid, cid=>cid] to a function that fails if you do not pass a string to it.

  • 🇨🇦Canada alberto56

    This assertion was added to Drupal core in 📌 [11.x] Adjust Database API to remove deprecated Drupal 10 code in Drupal 11 Fixed for Drupal 11.

    So presumably this module works in Drupal 10, although I have not tested it.

    The problematic code exists in abjs commit 6aaf7c4 - Drupal 11 compatiblility fixes, which to my understanding is the latest commit.

  • 🇨🇦Canada alberto56

    Confirming the module works on Drupal 10, but not Drupal 11. Changing the title accordingly

  • 🇮🇳India flutterstack

    I have cloned https://git.drupalcode.org/project/abjs.git and fixed the issue in patch #5. kindly review.

  • 🇨🇦Canada alberto56

    I'm setting to this RTBC as it works fine for me.

    Also setting this issue to critical as the Drupal 11 version does not work at all otherwise.

Production build 0.71.5 2024