BadRequestHttpException: Invalid contextual ID specified

Created on 31 October 2018, about 6 years ago
Updated 13 September 2024, 2 months ago

Hello,

We are running a Drupal 8.6.2 multisite and users have been reporting over the last few weeks that the the contextual links are disappearing on them. When I investigate, the links appear for me as admin, but do not for the user.

I am getting this error in the WatchDogs:

Location http://site.com/contextual/render
Message Symfony\Component\HttpKernel\Exception\BadRequestHttpException: Invalid contextual ID specified. in Drupal\contextual\ContextualController->render() (line 76 of /core/modules/contextual/src/ContextualController.php).
Severity Error

Rebuilding the Drupal cache fixes the issue.

I'm just wondering how this is happening? it seems to be random.

Thanks!

🐛 Bug report
Status

Closed: won't fix

Version

11.0 🔥

Component
Contextual 

Last updated about 2 months ago

Created by

🇨🇦Canada abryenton@gmail.com

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany thomaswalther Rhein-Main Area

    I upload a media video on drupal 10.0.8 (php 8.1.21).

    the upload is limited on "2 MB" on the server.

    so i changed via php.ini to

    upload_max_filesize = 16M
    post_max_size = 16M
    

    after that change, i could upload the video, but there occurs the error:
    Symfony\Component\HttpKernel\Exception\BadRequestHttpException: No contextual ids specified. in Drupal\contextual\ContextualController->render() (line 66 of /webroot/core/modules/contextual/src/ContextualController.php).

    Drupal shows the Error (german)
    Ein nicht behebbarer Fehler ist aufgetreten. Die Datei hat wahrscheinlich die maximale Dateigröße (16 MB) überschritten, die dieser Server unterstützt.

  • There is definitely a difference between DDEV and Pantheon on this. I see the error and contextual links don't load initially in DDEV until the caches are cleared. But with Pantheon I don't see the error, and there is no trouble with contextual links.

  • Ok, interesting findings. Start Docker desktop, ddev start, and go to the site, no contextual links are rendered and there is the following error in the dblog:
    Symfony\Component\HttpKernel\Exception\BadRequestHttpException: Invalid contextual ID specified. in Drupal\contextual\ContextualController->render() (line 78 of /var/www/html/web/core/modules/contextual/src/ContextualController.php).
    Then clear caches. (via Drush or UI) and all is better.
    Then ddev stop, ddev start. All is still fine.
    Shut down Docker desktop, and restart docker, then ddev start. Visit the site, and the problem is back exactly as it was.
    The only difference I can see from the command line is that the ddev-ssh-agent containers are recreated and started after having shut down docker:

     Container ddev-ssh-agent  Recreate 
     Container ddev-ssh-agent  Recreated 
     Container ddev-ssh-agent  Started 
    ssh-agent container is running: If you want to add authentication to the ssh-agent container, run 'ddev auth ssh' to enable your keys. 
  • Also, after clearing the cache and "fixing" it, ddev poweroff, and ddev start bring the problem back the same way that shutting down Docker does.

  • Ok, so DDEV users, here you go. Whenever ddev builds the containers, they create a new hash_salt everytime. You can reproduce this by opening the settings.ddev.php file, doing ddev poweroff, and then ddev start to view it change in real time.

    So if you place one of the hash_salt values ddev creates AFTER the loop in settings.php, this will allow that value to persist despite the new hash salt every start-up. Something like this:

    // Automatically generated include for settings managed by ddev.
    $ddev_settings = dirname(__FILE__) . '/settings.ddev.php';
    if (getenv('IS_DDEV_PROJECT') == 'true' && is_readable($ddev_settings)) {
      require $ddev_settings;
    }
    
    $settings['hash_salt'] = 'TjrGfXryltDjIfeIlxgbouWdUlOBXQaalBjXkgxsvbEYQowkqSZsDeraAyUzGUCT';
  • I bet this explains #27 🐛 BadRequestHttpException: Invalid contextual ID specified Postponed: needs info too. I'm guessing when you push a site from pantheon dev to test, there's a new hash_salt value for test environment.

    And once cache is cleared the problem doesn't come back.

  • 🇷🇴Romania ioana apetri

    I use ddev for lunching the Drupal - version 10.1.4.I am experiencing the same issue, but after clearing the cache it dissapeared. I also cannot indentify why do I have this error in the error logs.

  • Status changed to Closed: won't fix 2 months ago
  • 🇦🇺Australia acbramley

    This has been in PMNMI for almost 2 years and the comments since seem to indicate it is an issue in DDEV and has been fixed since.

    I am closing this issue. Please feel free to re-open with steps to reproduce from a fresh drupal installation if appropriate.

Production build 0.71.5 2024