Update constructor when #3100732: Allow specifying metadata on JSON:API objects lands

Created on 2 June 2024, about 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. By moving backwards one commit at a time in the git history, I traced the breakage to 🐛 Pages with default includes are not cached Fixed .

Drupal 10.2.6, PHP 8.3.

📌 Task
Status

Postponed

Version

3.0

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

  • 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 about 1 year ago
    17 pass, 2 fail
  • Status changed to Needs review about 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
    about 1 year ago
    #189168
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    27:41
    25:56
    Running
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    23:53
    21:57
    Running
  • Pipeline finished with Canceled
    about 1 year ago
    Total: 205s
    #189183
  • Status changed to Postponed about 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
    about 1 year ago
    Total: 249s
    #189190
  • Pipeline finished with Failed
    about 1 year ago
    Total: 388s
    #197583
  • Pipeline finished with Success
    about 1 year ago
    Total: 302s
    #197599
  • Pipeline finished with Success
    about 1 year ago
    Total: 204s
    #197669
  • Pipeline finished with Failed
    about 1 year ago
    Total: 296s
    #199193
  • Pipeline finished with Failed
    about 1 year ago
    Total: 303s
    #199219
  • Pipeline finished with Failed
    about 1 year ago
    Total: 301s
    #199239
  • Pipeline finished with Skipped
    about 1 year ago
    #199257
  • 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 Manual
    about 1 year ago
    #202696
  • 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: 266s
    #204990
  • Pipeline finished with Failed
    about 1 year ago
    Total: 195s
    #205012
  • Pipeline finished with Success
    about 1 year ago
    Total: 281s
    #205054
  • Pipeline finished with Success
    about 1 year ago
    Total: 277s
    #205098
  • Pipeline finished with Success
    about 1 year ago
    Total: 287s
    #205107
  • Pipeline finished with Success
    about 1 year ago
    Total: 279s
    #205409
  • Pipeline finished with Failed
    about 1 year ago
    Total: 283s
    #205429
  • Pipeline finished with Success
    about 1 year ago
    Total: 309s
    #205626
  • Pipeline finished with Success
    about 1 year ago
    Total: 296s
    #205631
  • Pipeline finished with Success
    about 1 year ago
    Total: 201s
    #212751
  • Pipeline finished with Failed
    12 months ago
    Total: 329s
    #215998
  • Pipeline finished with Canceled
    12 months ago
    Total: 365s
    #216504
  • Pipeline finished with Failed
    12 months ago
    Total: 266s
    #220047
  • Pipeline finished with Success
    12 months ago
    #220265
  • Pipeline finished with Skipped
    12 months ago
    #225649
  • Pipeline finished with Canceled
    11 months ago
    Total: 398s
    #235564
  • Pipeline finished with Success
    11 months ago
    Total: 417s
    #235565
  • Pipeline finished with Success
    11 months ago
    Total: 81s
    #240841
  • Pipeline finished with Success
    11 months ago
    #255671
  • Pipeline finished with Skipped
    11 months ago
    #256070
  • Pipeline finished with Failed
    11 months ago
    #262033
  • Pipeline finished with Failed
    10 months ago
    Total: 1708s
    #263399
  • Pipeline finished with Failed
    10 months ago
    Total: 315s
    #270430
  • Pipeline finished with Success
    10 months ago
    #270438
  • Pipeline finished with Success
    10 months ago
    Total: 164s
    #272600
  • Pipeline finished with Success
    10 months ago
    Total: 161s
    #272627
  • Pipeline finished with Failed
    10 months ago
    Total: 765s
    #272675
  • Pipeline finished with Failed
    10 months ago
    Total: 295s
    #276576
  • Pipeline finished with Failed
    10 months ago
    Total: 245s
    #285011
  • Pipeline finished with Failed
    10 months ago
    Total: 246s
    #286851
  • Pipeline finished with Skipped
    9 months ago
    #294096
  • Pipeline finished with Failed
    9 months ago
    Total: 492s
    #294134
  • Pipeline finished with Failed
    9 months ago
    Total: 178s
    #294635
  • Pipeline finished with Success
    9 months ago
    Total: 160s
    #294676
  • Pipeline finished with Failed
    9 months ago
    Total: 163s
    #299054
  • Pipeline finished with Failed
    9 months ago
    Total: 214s
    #299063
  • Pipeline finished with Success
    9 months ago
    Total: 174s
    #299079
  • Pipeline finished with Success
    9 months ago
    Total: 358s
    #299155
  • Pipeline finished with Canceled
    9 months ago
    Total: 80s
    #303675
  • Pipeline finished with Failed
    8 months ago
    Total: 316s
    #320023
  • Pipeline finished with Success
    8 months ago
    Total: 292s
    #320030
  • Pipeline finished with Failed
    8 months ago
    Total: 210s
    #321136
  • Pipeline finished with Failed
    8 months ago
    Total: 172s
    #321143
  • Pipeline finished with Failed
    8 months ago
    Total: 176s
    #321144
  • Pipeline finished with Failed
    8 months ago
    Total: 340s
    #321150
  • Pipeline finished with Success
    8 months ago
    #337690
  • Pipeline finished with Success
    8 months ago
    Total: 164s
    #337697
  • Pipeline finished with Success
    7 months ago
    Total: 142s
    #346232
  • Pipeline finished with Canceled
    7 months ago
    Total: 171s
    #350150
  • Pipeline finished with Canceled
    7 months ago
    Total: 112s
    #350161
  • Pipeline finished with Success
    7 months ago
    Total: 161s
    #350263
  • Pipeline finished with Success
    7 months ago
    Total: 148s
    #351011
  • Pipeline finished with Canceled
    7 months ago
    Total: 120s
    #360340
  • Pipeline finished with Success
    7 months ago
    Total: 149s
    #360342
  • Pipeline finished with Success
    7 months ago
    Total: 175s
    #360640
  • Pipeline finished with Success
    7 months ago
    Total: 178s
    #360656
  • Pipeline finished with Success
    7 months ago
    Total: 241s
    #367621
  • Pipeline finished with Canceled
    7 months ago
    Total: 80s
    #367704
  • Pipeline finished with Success
    7 months ago
    Total: 143s
    #367712
  • Pipeline finished with Success
    7 months ago
    #368430
  • Pipeline finished with Success
    7 months ago
    Total: 235s
    #369090
  • Pipeline finished with Success
    7 months ago
    Total: 145s
    #374054
  • Pipeline finished with Success
    6 months ago
    Total: 165s
    #379043
  • Pipeline finished with Success
    6 months ago
    Total: 167s
    #380639
  • Pipeline finished with Success
    6 months ago
    Total: 165s
    #380643
  • Pipeline finished with Success
    6 months ago
    Total: 167s
    #380650
  • Pipeline finished with Success
    5 months ago
    Total: 193s
    #401638
  • Pipeline finished with Success
    4 months ago
    Total: 195s
    #429228
  • Pipeline finished with Success
    4 months ago
    Total: 315s
    #429285
  • Pipeline finished with Success
    4 months ago
    Total: 204s
    #432122
  • Pipeline finished with Success
    4 months ago
    Total: 152s
    #438013
  • Pipeline finished with Success
    4 months ago
    Total: 279s
    #444710
  • Pipeline finished with Success
    4 months ago
    Total: 290s
    #445359
  • Pipeline finished with Success
    4 months ago
    Total: 274s
    #445499
  • Pipeline finished with Success
    4 months ago
    Total: 292s
    #447438
  • Pipeline finished with Success
    4 months ago
    Total: 383s
    #452508
  • Pipeline finished with Failed
    2 months ago
    Total: 169s
    #485009
  • Pipeline finished with Canceled
    2 months ago
    Total: 200s
    #485025
  • Pipeline finished with Success
    2 months ago
    #485223
  • Pipeline finished with Failed
    about 1 month ago
    Total: 225s
    #507547
  • Pipeline finished with Success
    about 1 month ago
    Total: 245s
    #507577
  • Pipeline finished with Success
    about 1 month ago
    Total: 269s
    #510631
  • Pipeline finished with Success
    about 1 month ago
    Total: 184s
    #513267
  • Pipeline finished with Success
    19 days ago
    Total: 130s
    #522578
  • Pipeline finished with Success
    19 days ago
    Total: 168s
    #522915
  • Pipeline finished with Success
    11 days ago
    Total: 237s
    #529434
  • 🇫🇷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
    7 days 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 days ago
    #535653
  • Merge request !68Fix constructor in backwards-compatible way → (Open) created by ptmkenny
  • Pipeline finished with Failed
    3 days ago
    #535659
  • Pipeline finished with Failed
    3 days ago
    #535664
  • Pipeline finished with Success
    3 days ago
    #535671
  • First commit to issue fork.
  • Pipeline finished with Running
    3 days 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 days ago
    Total: 384s
    #535828
  • Pipeline finished with Success
    2 days ago
    Total: 133s
    #536832
  • Pipeline finished with Canceled
    2 days ago
    Total: 50s
    #536939
  • Pipeline finished with Failed
    about 17 hours ago
    Total: 155s
    #538350
Production build 0.71.5 2024