Problem/Motivation

500 error after updating the module to 2.1.0.

Steps to reproduce

1. Use composer to update the module to 2.1.0.
2. Run update.php or drush updb.
3. 500 error.

Proposed resolution

Add a hook_update to force cache rebuild after updating to 2.1.x.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#7 3279371-7-post-update.patch438 bytestr

Comments

xmacinfo created an issue. See original summary.

xmacinfo’s picture

Error message before forcing a cache rebuild

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException : You have requested a non-existent service "honeypot". dans Drupal\Component\DependencyInjection\Container->get() (ligne 156 de /home/sitename/public_html/web/core/lib/Drupal/Component/DependencyInjection/Container.php).

tr’s picture

Did you run update.php?

hassebasse’s picture

I also had problems and what solved it was drush cache-rebuild. Update PHP didn't make any difference, so it was not a DB issue.

Thank you xmacinfo

tr’s picture

The 'honeypot' service is new in the 2.1.x branch, so the ServiceNotFoundException is expected if you don't rebuild the service container. When the service container is rebuilt then Drupal will know about the new service.

update.php rebuilds the service container.

drush cr also rebuilds the service container.

When you composer update a module, you must always run update.php. This is well documented. This is not something that a contributed module like Honeypot is responsible for. If you don't run update.php, then having a hook_update_N() to clear the cache isn't going to do anything because that hook will never be run either.

Note that introducing a service in a minor-point release and deprecating the procedural functions is an extremely common change in Drupal core, and never requires a hook_update_N() to rebuild the cache.

xmacinfo’s picture

Issue summary: View changes

@TR

Please note that each time I update a module, I run update.php.

The bug here is that AFTER running update.php, the site still emits a 500 error.

Watchdog output:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException : You have requested a non-existent service "honeypot". dans Drupal\Component\DependencyInjection\Container->get() (ligne 156 de /home/sitename/public_html/web/core/lib/Drupal/Component/DependencyInjection/Container.php).

Note that introducing a service in a minor-point release and deprecating the procedural functions is an extremely common change in Drupal core, and never requires a hook_update_N() to rebuild the cache.

Then the error may be an incomplete service that update.php does not discover properly.

tr’s picture

StatusFileSize
new438 bytes

I don't think there's any problem with the service definition - if there were then rebuilding the cache wouldn't have fixed it ...

It really does seem that your container doesn't know about the 'honeypot' service - that's what the error message is saying. But as I said, the container should be rebuilt when update.php is run. It may be just that a cache rebuild is always necessary after updating a module (I know I always do this out of habit, and a lot of the "official" Drupal documentation says to do this.) An updated module may have changed class names and namespaces (internal names, part of the implementation not the module API), added or updated service definitions, etc. All these are allowable changes in minor point updates. But I really don't think rebuilding the cache is something that a contributed module should be doing or should have to do in order to make allowable updates work properly.

Regardless, I could add this empty post-update hook, but it seems a little silly. This is occasionally done in core and some contributed modules, but is certainly not the norm as far as I can tell. Would it be possible for you to test it by re-running the update with this patch?

tneo’s picture

I had the same issue in a multi-site set-up. I was not able to log-in into a site. Forcing the update.php to run for the affected site resolved the issue.

yktdan’s picture

I got the site running by clearing the cache with phpmyadmin. After doing so I ran update.php and it said no updates. I do not have drush installed so that is not an option for me (and probably many who are not site developers). I take this to mean that clearing cache is the important operation, not running update. If you are logged on as admin when you run composer update, your site is down and manually clearing the cache may be the only option.

john_b’s picture

Update to Honeypot 2.1 on PHP 8.1 also crashed my site.

WD error TypeError: Drupal\honeypot\HoneypotService::getProtectedForms(): Return value must be of type array, null returned in Drupal\honeypot\HoneypotService->getProtectedForms() (line 164

Cache rebuild with 'drush cr' fixed it.

xmacinfo’s picture

Status: Active » Reviewed & tested by the community

Tested the patch in #7 directly on 2.1.0 and it solves the issue.

Site 1a

  1. Ran composer update to update Honeypot to 2.1.0.
  2. Copied the patch to the module folder and ran git apply.
  3. Ran drush updb.
  4. Checks the /contact page loads correctly.

Site 1b, to double verify

  1. Ran composer update to update Honeypot to 2.1.0.
  2. Ran drush updb.
  3. Checks the /contact crashes, same error as in #6.
  4. Copied the patch to the module folder and ran git apply.
  5. Ran drush updb.
  6. Checks the /contact page loads correctly.

Marking RTBC.

Thanks.

  • TR committed 9992abc on 2.1.x
    Issue #3279371 by TR, xmacinfo: Upgrading to 2.1.x required a cache...
tr’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for testing it @xmacinfo - that helps a lot!

Committed.

tr’s picture

Version: 2.1.0 » 2.1.x-dev

Status: Fixed » Closed (fixed)

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