FieldTypeUninstallValidator: TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, null given in str_starts_with()

Created on 31 July 2024, 5 months ago
Updated 13 September 2024, 3 months ago

Overview

While uninstalling the module getting below error:
TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, null given in str_starts_with()

Steps to reproduce

  1. Go to uninstall page /admin/modules/uninstall

Proposed resolution

User interface changes

None.

๐Ÿ› Bug report
Status

Fixed

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia bhuvaneshwar

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @bhuvaneshwar
  • Assigned to bhuvaneshwar
  • Status changed to Postponed: needs info 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Thanks for reporting this! But โ€ฆ it's a mystery to me how to reproduce this, since tests are passing and no backtrace is included.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia bhuvaneshwar

    So, when I try to uninstall XB, I encounter this error or by going to the uninstall page.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia bhuvaneshwar

    Here is the stack trace:

    TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, null given in str_starts_with() (line 140 of /var/www/html/modules/experience_builder/src/FieldTypeUninstallValidator.php).
    
    #0 /var/www/html/modules/experience_builder/src/FieldTypeUninstallValidator.php(140): str_starts_with()
    #1 /var/www/html/modules/experience_builder/src/FieldTypeUninstallValidator.php(56): Drupal\experience_builder\FieldTypeUninstallValidator->checkDefaultValueUses()
    #2 /var/www/html/core/lib/Drupal/Core/Extension/ModuleInstaller.php(645): Drupal\experience_builder\FieldTypeUninstallValidator->validate()
    #3 /var/www/html/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(99): Drupal\Core\Extension\ModuleInstaller->validateUninstall()
    #4 /var/www/html/core/modules/system/src/Form/ModulesUninstallForm.php(161): Drupal\Core\ProxyClass\Extension\ModuleInstaller->validateUninstall()
    #5 [internal function]: Drupal\system\Form\ModulesUninstallForm->buildForm()
    #6 /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array()
    #7 /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php(284): Drupal\Core\Form\FormBuilder->retrieveForm()
    #8 /var/www/html/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
    #9 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
    #10 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
    #11 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #12 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
    #13 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
    #14 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #15 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #16 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
    #17 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #18 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #19 /var/www/html/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
    #20 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
    #21 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
    #22 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #23 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #24 /var/www/html/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #25 /var/www/html/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #26 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(736): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #27 /var/www/html/index.php(19): Drupal\Core\DrupalKernel->handle()
    #28 {main}
  • Status changed to Active 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Aha! Nice catch! ๐Ÿ‘

    That's something that we should be able to add explicit test coverage for pretty easily I think? ๐Ÿ˜Š

  • Issue was unassigned.
  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia bhuvaneshwar

    Test needs to be added

  • Pipeline finished with Failed
    5 months ago
    Total: 481s
    #245294
  • First commit to issue fork.
  • Assigned to wim leers
  • Status changed to Needs review 5 months ago
  • @wimleers I just added the tests asserting that we are able to load the page which was not happening prior to this fix.Is there something else that needs to be a part of this test?Assigning it to you for the clarifications on this.

  • Issue was unassigned.
  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    LGTM!

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    I was wrong:

    P.S.: I ran the test-only CI job and it passed tests: https://git.drupalcode.org/project/experience_builder/-/jobs/2379770 โ€” which means that there was indeed a test failure, which means that this MR contains the appropriate test coverage. ๐Ÿ‘

    That CI job should've failed. The test passes locally without the code changes.

  • Assigned to wim leers
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Found the root cause: the test assertion was inverted โ€ฆ which meant it always passes.

    Fixed.

  • Issue was unassigned.
  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • Assigned to utkarsh_33
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    If you agree with my changes, then the honor is all yours to merge this MR, @Utkarsh_33! ๐Ÿ˜„

  • Issue was unassigned.
  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Too bad, the test fails on PostgreSQL for some reason ๐Ÿคทโ€โ™€๏ธ See https://git.drupalcode.org/project/experience_builder/-/jobs/2380752

    To debug this, add

    var_dump($this->getSession()->getPage()->getContent());
    

    temporarily before the failing assertion.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • First commit to issue fork.
  • Pipeline finished with Failed
    4 months ago
    Total: 389s
    #259219
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    https://issue.pages.drupalcode.org/-/experience_builder-3464830/-/jobs/2...

    The website encountered an unexpected error. Try again later.
    
    Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42883]: Undefined function: 7 ERROR: function json_extract(jsonb, unknown) does not exist LINE 4: WHERE (JSON_EXTRACT(field_xb_demo_props, '$.*.*.expression')... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.: SELECT "node__field_xb_demo"."entity_id" AS "entity_id", "node__field_xb_demo"."revision_id" AS "revision_id" FROM "test69047609node__field_xb_demo" "node__field_xb_demo" WHERE (JSON_EXTRACT(field_xb_demo_props, '$.*.*.expression')::text LIKE '%โ„น๏ธŽcommentโŸ%'); Array ( ) in Drupal\experience_builder\FieldTypeUninstallValidator->checkContentEntityUses() (line 212 of /builds/issue/experience_builder-3464830/src/FieldTypeUninstallValidator.php).
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Okay, so this error on PostgreSQL:

    ERROR: function json_extract(jsonb, unknown) does not exist
    

    is expected.

    What is not expected, is that this runs at all, because we have

        if (!isset($connection_info['default']['driver']) || $connection_info['default']['driver'] !== 'mysql') {
          $this->markTestSkipped('This test only runs for the MySQL database driver. See https://drupal.org/i/3452756');
        }
    

    in FieldTypeUninstallValidatorTest.

    Conclusion: we expect that UninstallModulePageTest will fail on PostgreSQL too. We have ๐Ÿ“Œ Ensure querying JSON nested values when parent keys are unknown is possible in all supported databases Active for this.

    So this needs a slight adjustment to the new UninstallModulePageTest and then it'll be good to go ๐Ÿ‘

  • First commit to issue fork.
  • Pipeline finished with Failed
    4 months ago
    Total: 858s
    #263015
  • Pipeline finished with Failed
    4 months ago
    Total: 441s
    #263053
  • Pipeline finished with Success
    4 months ago
    Total: 552s
    #263055
  • Status changed to Needs review 4 months ago
  • As per #20 ๐Ÿ› FieldTypeUninstallValidator: TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, null given in str_starts_with() Needs work , tweak code of UninstallModulePageTest so that test skip for PostgreSQL only as it fails for this one.

    Also observed there are some pipeline failures related : \ComponentValidationTest::randomMachineName() , for this rebased the MR.

    Please review, moving NR

  • Pipeline finished with Failed
    4 months ago
    Total: 930s
    #263086
  • Pipeline finished with Success
    4 months ago
    Total: 459s
    #263106
  • Pipeline finished with Failed
    4 months ago
    Total: 371s
    #263444
  • Pipeline finished with Success
    4 months ago
    Total: 414s
    #263446
  • Pipeline finished with Success
    4 months ago
    Total: 432s
    #263451
  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Getting close!

  • Pipeline finished with Success
    4 months ago
    Total: 1024s
    #264836
  • Status changed to Needs review 4 months ago
  • Addressed the feedback, Please review, moving to NR

  • Pipeline finished with Success
    4 months ago
    Total: 511s
    #264868
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia atul_ghate

    Hi,

    I reviewed MR!143, applied it against Experience Builder 0.x, and confirmed that I can go to the uninstall page without any errors. I was also able to uninstall the module and verified that the module is working correctly.

    Iโ€™ve added a before-and-after screen recording for reference. RTBC+

    Thank you.

  • Pipeline finished with Success
    4 months ago
    Total: 522s
    #266975
  • Status changed to RTBC 4 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    The test-only CI job indeed reproduces the reported bug:

    There was 1 error:
    1) Drupal\Tests\experience_builder\Functional\UninstallModulePageTest::testUninstallModulePage
    Exception: Warning: Undefined array key "expression"
    Drupal\experience_builder\FieldTypeUninstallValidator->checkDefaultValueUses()() (Line: 140)
    

    โ€” https://git.drupalcode.org/issue/experience_builder-3464830/-/jobs/2575834

    ๐Ÿ‘

    Time to ship this! ๐Ÿšข Thanks all ๐Ÿ™

    P.S.: @atul_ghate: please do not post screenshots of a patch successfully applying. That is not remotely helpful. If the MR applies, we already know that it's an applicable patch โ€ฆ

  • Pipeline finished with Skipped
    4 months ago
    #267967
  • Pipeline finished with Skipped
    4 months ago
    #267969
  • Pipeline finished with Skipped
    4 months ago
    #267970
  • Status changed to Fixed 4 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Kristen Pol Santa Cruz, CA, USA

    Perhaps a follow-up issue is needed?

    kristens-mbp-2:starshot-xb kristenpol$ ddun experience_builder
    
    In PmCommands.php line 200:
                                                                                                                                             
      experience_builder: The <em class="placeholder">Experience Builder</em> field type is used in the following field: node.field_xb_demo  
                                                                                                                                             
    
    Failed to run drush pm:uninstall experience_builder: exit status 1
    
    
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    #29: That's Drupal core's \Drupal\field\FieldUninstallValidator, not XB.

    Before uninstall the XB module, you have to first delete all XB field instances. That's true for any module providing a field type.

    So no, no follow-up is needed for that ๐Ÿ˜‡

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Kristen Pol Santa Cruz, CA, USA

    Ah yes of courseโ€ฆ brain is mush.

    I have seen some modules that maybe had a friendlier error message or maybe Iโ€™m hallucinating at this point ๐Ÿ˜œ

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    @kristen pol The message is much friendlier also for this scenario โ€ฆ if you use the UI. There's only so much that's possible in a drush CLI context :)

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024