Clean URLs disappearing in Drupal 8
My team and I were a few days away from launching materialise.com, a brand new Drupal 8 website for a 3D printing company.
The website had been running smoothly for the past few weeks and we were confident that no major issues were left. Unfortunately, after some time we started noticing some strange behavior regarding the URL aliases of the nodes.
Pages losing Pretty Path
Our client reported that some pages had lost their Pretty Path, while those pages had not been edited by anyone in a while. The curious thing was that the checkbox for automatically creating a URL alias was checked, but the value was empty. No errors were to be found in the logs, and by simply re-saving those pages, the alias started working again.
Missing entry nodes
When taking a closer look at the database table where Pathauto stores itsaliases (url_alias), I discovered that the entries for those nodes were simply missing. The next step was to look into the source code of the Pathauto module and to try to find methods that allowed us to delete aliases from the database. By adding custom error logs to these methods, we quickly discovered the cause of the problem.
The source of the problem
When you delete a node, the deleteBySourcePrefix() method of Pathauto requests all aliases assigned to that node and deletes them. The query responsible for selecting the URL aliases to be deleted, matched all nodes with the following pattern: “/node/id*” where * is a wildcard. This effectively returns the node you want to delete, e.g. node/51 but unfortunately also nodes 510, 511, 512, … were being selected.
In reality, the query has to select the node itself (node/51) and all of its subpages (node/51/draft, node/51/edit, …). After finding the root of the problem, fixing it was pretty easy. I posted the bug along with my proposed solution on drupal.org and a few days later the fix was included in the development release of Pathauto, one of the most used modules in Drupal.
Helping the Drupal community
This is just a small example of how we not only fix bugs in our own projects, but also contribute back to the Drupal community to help improve the framework.
If you are a developing a website in Drupal 8 which uses Pathauto 8.x-1.0-beta1 or a dev release from before December 6th, I recommend updating to the latest dev release to avoid this bug.
The technical details about the bug can be found on drupal.org
Update: A new beta version of the Pathautho module was released on 01/18 which includes the fix for this bug. You can upgrade now to prevent this from happening on your site.
Op zoek naar innovatieve manieren om te groeien?Neem contact op