TypeError: Drupal\jsonapi_defaults\Controller\EntityResource::__construct(): Argument #12 must be of type JsonapiDefaultsInterface

Created on 2 June 2024, over 1 year ago

Problem/Motivation

After upgrading from 3.24 to 3.25, when I try to run drush updatedb or drush cr, I get the following error:

 [error]  TypeError: Drupal\jsonapi_defaults\Controller\EntityResource::__construct(): Argument #12 ($jsonapi_defaults) must be of type Drupal\jsonapi_defaults\JsonapiDefaultsInterface, Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher given in Drupal\jsonapi_defaults\Controller\EntityResource->__construct() (line 75 of /var/www/html/web/modules/contrib/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php) #0 [internal function]: Drupal\jsonapi_defaults\Controller\EntityResource->__construct()

Reverting to 3.24 clears the error. I will now try to track down which commit caused this.

πŸ› Bug report
Status

Active

Version

3.25

Component

Code

Created by

πŸ‡―πŸ‡΅Japan ptmkenny

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

Merge Requests

Comments & Activities

  • Pipeline finished with Skipped
    about 2 years ago
    #12768
  • Issue created by @ptmkenny
  • πŸ‡―πŸ‡΅Japan ptmkenny

    Full stacktrace:

    Fatal error: Uncaught TypeError: Drupal\jsonapi_defaults\Controller\EntityResource::__construct(): Argument #12 ($jsonapi_defaults) must be of type Drupal\jsonapi_defaults\JsonapiDefaultsInterface, Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher given, called in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 and defined in /var/www/html/web/modules/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php:75
    Stack trace:
    #0 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(259): Drupal\jsonapi_defaults\Controller\EntityResource->__construct()
    #1 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService()
    #2 /var/www/html/web/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php(20): Drupal\Component\DependencyInjection\Container->get()
    #3 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityResolverManager.php(106): Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition()
    #4 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityResolverManager.php(219): Drupal\Core\Entity\EntityResolverManager->getControllerClass()
    #5 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EntityRouteAlterSubscriber.php(48): Drupal\Core\Entity\EntityResolverManager->setRouteOptions()
    #6 [internal function]: Drupal\Core\EventSubscriber\EntityRouteAlterSubscriber->onRoutingRouteAlterSetType()
    #7 /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
    #8 /var/www/html/web/core/lib/Drupal/Core/Routing/RouteBuilder.php(189): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
    #9 /var/www/html/web/core/lib/Drupal/Core/ProxyClass/Routing/RouteBuilder.php(83): Drupal\Core\Routing\RouteBuilder->rebuild()
    #10 /var/www/html/web/core/includes/common.inc(485): Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild()
    #11 /var/www/html/web/core/includes/utility.inc(41): drupal_flush_all_caches()
    #12 /var/www/html/vendor/drush/drush/src/Commands/core/CacheRebuildCommands.php(70): drupal_rebuild()
    #13 [internal function]: Drush\Commands\core\CacheRebuildCommands->rebuild()
    #14 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array()
    #15 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
    #16 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
    #17 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(387): Consolidation\AnnotatedCommand\CommandProcessor->process()
    #18 /var/www/html/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
    #19 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run()
    #20 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
    #21 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
    #22 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run()
    #23 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun()
    #24 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run()
    #25 /var/www/html/vendor/drush/drush/drush(4): require('...')
    #26 /var/www/html/vendor/bin/drush(119): include('...')
    #27 {main}
      thrown in /var/www/html/web/modules/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php on line 75
     [warning] Drush command terminated abnormally.
    
  • Merge request !51inject event_dispatcher β†’ (Closed) created by ptmkenny
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    17 pass, 2 fail
  • Status changed to Needs review over 1 year ago
  • πŸ‡―πŸ‡΅Japan ptmkenny

    The eventDispatcher never got injected, but it is provided by core, so then in construct() all the arguments get out of order, breaking the site. This MR injects the eventDispatcher so that the parent constructor can be called properly.

  • Pipeline finished with Failed
    over 1 year ago
    #189168
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    11:49
    10:04
    Running
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    8:01
    6:05
    Running
  • Pipeline finished with Canceled
    over 1 year ago
    Total: 205s
    #189183
  • Status changed to Postponed over 1 year ago
  • πŸ‡―πŸ‡΅Japan ptmkenny

    So this issue was caused by me having applied the MR in ✨ Allow specifying `meta` data on JSON:API objects Needs work . When this issue eventually gets committed to core, the code will need to be updated, so I'm marking postponed for now. But feel free to close if you would rather handle this once the commit actually happens.

  • Pipeline finished with Failed
    over 1 year ago
    Total: 249s
    #189190
  • Pipeline finished with Failed
    over 1 year ago
    Total: 388s
    #197583
  • Pipeline finished with Success
    over 1 year ago
    Total: 281s
    #197591
  • Pipeline finished with Success
    over 1 year ago
    Total: 204s
    #197669
  • Pipeline finished with Failed
    over 1 year ago
    Total: 298s
    #199186
  • Pipeline finished with Failed
    over 1 year ago
    Total: 301s
    #199239
  • Pipeline finished with Skipped
    over 1 year ago
    #199257
  • Pipeline finished with Failed
    over 1 year ago
    Total: 292s
    #199272
  • Pipeline finished with Success
    about 1 year ago
    Total: 151s
    #200133
  • Pipeline finished with Success
    about 1 year ago
    Total: 144s
    #200846
  • Pipeline finished with Skipped
    about 1 year ago
    #204135
  • Pipeline finished with Success
    about 1 year ago
    Total: 281s
    #204976
  • Pipeline finished with Success
    about 1 year ago
    Total: 312s
    #204981
  • Pipeline finished with Success
    about 1 year ago
    Total: 281s
    #205054
  • Pipeline finished with Failed
    about 1 year ago
    Total: 283s
    #205429
  • Pipeline finished with Skipped
    about 1 year ago
    #211735
  • Pipeline finished with Failed
    about 1 year ago
    Total: 329s
    #215998
  • Pipeline finished with Success
    about 1 year ago
    #220265
  • Pipeline finished with Skipped
    about 1 year ago
    #225649
  • Pipeline finished with Failed
    about 1 year ago
    Total: 392s
    #233781
  • Pipeline finished with Canceled
    about 1 year ago
    Total: 398s
    #235564
  • Pipeline finished with Success
    about 1 year ago
    Total: 417s
    #235565
  • Pipeline finished with Success
    about 1 year ago
    #255671
  • Pipeline finished with Failed
    about 1 year ago
    Total: 1708s
    #263399
  • Pipeline finished with Failed
    about 1 year ago
    Total: 151s
    #263466
  • Pipeline finished with Failed
    about 1 year ago
    Total: 187s
    #272588
  • Pipeline finished with Failed
    about 1 year ago
    Total: 196s
    #272593
  • Pipeline finished with Success
    about 1 year ago
    Total: 174s
    #272617
  • Pipeline finished with Failed
    about 1 year ago
    Total: 158s
    #272657
  • Pipeline finished with Failed
    about 1 year ago
    Total: 295s
    #276576
  • Pipeline finished with Failed
    12 months ago
    Total: 206s
    #284949
  • Pipeline finished with Failed
    12 months ago
    Total: 245s
    #285011
  • Pipeline finished with Skipped
    12 months ago
    #294096
  • Pipeline finished with Failed
    12 months ago
    Total: 177s
    #294658
  • Pipeline finished with Failed
    12 months ago
    Total: 163s
    #299054
  • Pipeline finished with Failed
    12 months ago
    Total: 214s
    #299063
  • Pipeline finished with Success
    12 months ago
    Total: 174s
    #299079
  • Pipeline finished with Success
    11 months ago
    Total: 231s
    #303676
  • Pipeline finished with Canceled
    11 months ago
    #303677
  • Pipeline finished with Success
    11 months ago
    Total: 292s
    #320030
  • Pipeline finished with Failed
    11 months ago
    Total: 210s
    #321136
  • Pipeline finished with Failed
    11 months ago
    Total: 172s
    #321143
  • Pipeline finished with Failed
    11 months ago
    Total: 340s
    #321150
  • Pipeline finished with Success
    10 months ago
    #337690
  • Pipeline finished with Canceled
    10 months ago
    Total: 112s
    #350161
  • Pipeline finished with Success
    10 months ago
    Total: 161s
    #350263
  • Pipeline finished with Success
    10 months ago
    Total: 148s
    #351011
  • Pipeline finished with Success
    9 months ago
    Total: 130s
    #359453
  • Pipeline finished with Success
    9 months ago
    Total: 149s
    #360342
  • Pipeline finished with Success
    9 months ago
    Total: 370s
    #367638
  • Pipeline finished with Canceled
    9 months ago
    Total: 80s
    #367704
  • Pipeline finished with Success
    9 months ago
    Total: 143s
    #367712
  • Pipeline finished with Success
    9 months ago
    #368430
  • Pipeline finished with Success
    9 months ago
    Total: 203s
    #374204
  • Pipeline finished with Success
    9 months ago
    Total: 164s
    #379034
  • Pipeline finished with Success
    9 months ago
    Total: 167s
    #380639
  • Pipeline finished with Success
    8 months ago
    Total: 193s
    #401638
  • Pipeline finished with Failed
    7 months ago
    Total: 191s
    #422219
  • Pipeline finished with Canceled
    7 months ago
    Total: 55s
    #429049
  • Pipeline finished with Success
    6 months ago
    Total: 194s
    #440769
  • Pipeline finished with Success
    6 months ago
    Total: 290s
    #445359
  • Pipeline finished with Success
    6 months ago
    Total: 274s
    #445499
  • Pipeline finished with Success
    6 months ago
    Total: 292s
    #447438
  • Pipeline finished with Success
    6 months ago
    Total: 383s
    #452508
  • Pipeline finished with Failed
    5 months ago
    Total: 169s
    #485009
  • Pipeline finished with Success
    5 months ago
    #485223
  • Pipeline finished with Success
    5 months ago
    #486067
  • Pipeline finished with Failed
    4 months ago
    Total: 225s
    #507547
  • Pipeline finished with Failed
    4 months ago
    Total: 247s
    #509573
  • Pipeline finished with Success
    4 months ago
    #510572
  • Pipeline finished with Success
    3 months ago
    Total: 231s
    #516702
  • Pipeline finished with Skipped
    3 months ago
    #516706
  • Pipeline finished with Success
    3 months ago
    Total: 130s
    #522578
  • Pipeline finished with Success
    3 months ago
    Total: 130s
    #522579
  • Pipeline finished with Success
    3 months ago
    Total: 153s
    #523820
  • πŸ‡«πŸ‡·France jchatard

    I'm trying to upgrade a Drupal 10.x webiste to 11.x and encounter this error.

    I'm not entirely sure to understand if the patch was merged to the main branch?

  • πŸ‡«πŸ‡·France jchatard

    So after digging I can confirm that the patch wasn't merged and is working for the upgrade process.

  • πŸ‡―πŸ‡΅Japan ptmkenny

    Thanks, but this can't be RTBC yet because the change is not backwards compatible with Drupal < 11.2 (when the metadata feature became available).

  • Pipeline finished with Failed
    3 months ago
    Total: 347s
    #532684
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    I'm facing the same issue.
    Thanks for the MR
    Hoping for a new branch 4.0.x to manage this fix in a smoother way.

  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    Attached a static jsonapi_extras--2025-06-30--3452036--mr-51.patch file, to this point of MR51.
    To be used with Composer Patches and Drupal ~11.2.0

  • πŸ‡―πŸ‡΅Japan ptmkenny

    Bumping to major because this actually breaks sites that use 11.2+.

  • Pipeline finished with Failed
    3 months ago
    #535653
  • Pipeline finished with Failed
    3 months ago
    #535659
  • Pipeline finished with Failed
    3 months ago
    #535664
  • Pipeline finished with Success
    3 months ago
    #535671
  • First commit to issue fork.
  • Pipeline finished with Running
    3 months ago
    #535732
  • Put up alternate suggestion in MR 69.
    This uses setter injection via method calls in the service definition to avoid overriding the constructor altogether.

  • Pipeline finished with Success
    3 months ago
    Total: 384s
    #535828
  • Pipeline finished with Success
    2 months ago
    Total: 133s
    #536832
  • Pipeline finished with Canceled
    2 months ago
    Total: 50s
    #536939
  • Pipeline finished with Failed
    2 months ago
    Total: 361s
    #543495
  • Pipeline finished with Success
    2 months ago
    Total: 367s
    #543776
  • Pipeline finished with Failed
    2 months ago
    Total: 223s
    #544457
  • Pipeline finished with Success
    about 2 months ago
    Total: 816s
    #550452
  • Pipeline finished with Success
    about 2 months ago
    Total: 309s
    #559381
  • Pipeline finished with Success
    about 2 months ago
    Total: 262s
    #559383
  • Pipeline finished with Failed
    about 2 months ago
    Total: 359s
    #559807
  • Pipeline finished with Success
    about 2 months ago
    Total: 374s
    #561721
  • Pipeline finished with Success
    about 1 month ago
    Total: 154s
    #565340
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    I was asking myself: "Why isn't this using setter injection?" when I noticed this issue and saw that @godotislate did exactly that. So huge +1 for MR 69 as it's both forward and backward compatible. We should not be juggling with version_compare for this (MR 68).

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    kristiaanvandeneynde β†’ changed the visibility of the branch bad_di_fix_with_bc to hidden.

  • Pipeline finished with Success
    about 1 month ago
    Total: 211s
    #571634
  • Pipeline finished with Success
    about 1 month ago
    Total: 136s
    #572157
  • πŸ‡ΊπŸ‡ΈUnited States AaronBauman Philadelphia

    working for me, +1 RTBC, thanks

  • πŸ‡³πŸ‡±Netherlands bbrala Netherlands

    Thanks all! This is looking great.

  • πŸ‡³πŸ‡±Netherlands bbrala Netherlands
  • Pipeline finished with Success
    20 days ago
    Total: 397s
    #581480
  • Pipeline finished with Success
    20 days ago
    #581689
  • Pipeline finished with Success
    20 days ago
    Total: 324s
    #581747
  • Pipeline finished with Failed
    17 days ago
    #584494
  • Pipeline finished with Failed
    17 days ago
    #584524
  • Pipeline finished with Failed
    17 days ago
    #584546
  • Pipeline finished with Success
    11 days ago
    Total: 189s
    #589288
  • Status changed to Fixed 11 days ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Pipeline finished with Success
    10 days ago
    Total: 279s
    #590959
  • Pipeline finished with Success
    4 days ago
    Total: 160s
    #595869
  • Pipeline finished with Success
    3 days ago
    Total: 543s
    #596088
  • Pipeline finished with Failed
    2 days ago
    #597147
  • Pipeline finished with Canceled
    2 days ago
    #597219
  • Pipeline finished with Failed
    2 days ago
    #597238
Production build 0.71.5 2024