I have a view of article nodes with a path of /articles and one contextual filter. Therefore the URL path /articles/my-category would load the view with my-category as the contextual filter value. In previous versions of Drupal I could also have a pathauto alias of articles/[node:title] which would load the individual node, eg articles/test-article. I understand there could be a naming collision if a category name matched an article name, but found this to rarely be a problem.
In the latest D8 version I get this error:
The website encountered an unexpected error. Please try again later.
Drupal\Core\Entity\EntityStorageException: The given alias pattern (/articles/test-article-0) always matches the route view.articles.page_1 in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 757 of core\lib\Drupal\Core\Entity\Sql\SqlContentEntityStorage.php).
Drupal\pathauto\AliasUniquifier->isReserved('/articles/test-article-0', '/node/32', 'en')
Drupal\pathauto\AliasUniquifier->uniquify('/articles/test-article-0', '/node/32', 'en')
Drupal\pathauto\PathautoGenerator->createEntityAlias(Object, 'insert')
Drupal\pathauto\PathautoGenerator->updateEntityAlias(Object, 'insert')
pathauto_entity_insert(Object)
call_user_func_array('pathauto_entity_insert', Array)
...
However if I manually add the alias to the article node there is no problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #52 | the_given_alias_pattern-2655874-52.patch | 9.61 KB | juampynr |
| #49 | the_given_alias_pattern-2655874-49.patch | 9.69 KB | juampynr |
| #49 | Selection_003.png | 52.06 KB | juampynr |
| #49 | Selection_002.png | 51.79 KB | juampynr |
| #39 | use-test-view-2655874-15.patch | 9.53 KB | juampynr |
Comments
Comment #2
mstrelan commentedFWIW \Drupal\path\Form\PathFormBase::validateForm() doesn't check if a manually entered path is in use by another route so perhaps for consistency Pathauto shouldn't either.
Comment #3
berdirpathauto in 7.x did something similar too, but it apparently didn't trigger those kind of matches.
We could remove it, but automatic aliases can be problematic, especially if you have something like a top-level /[node:title] alias, it would be very easy to accidently make pages like /user in accessible. That's much less likely to happen with manual aliases.
Comment #4
Anonymous (not verified) commentedIn my case the issue was generated by "Transliterate prior to creating alias" or "Reduce strings to letters and numbers" in "Settings" tab. I disabled both of them. However, when using "Bulk generate" I still get issues. The last one was "An error occurred while processing with arguments :". When generating the aliases from the content page (/admin/content) I get no issues.
Comment #5
Anonymous (not verified) commentedAlso I don't think the error message is right. It shows the current path, which the module tried to assign but it should show the pattern used to generate the path. It says "The given alias pattern" but it outputs a calculated path.
Comment #6
dave reidHrm, we had the same check in D7, but it wouldn't return FALSE positives, which it seems to be doing with Views paths now in D8. @Berdir: Do you know is this validation coming from Pathauto or Core?
Comment #7
dave reidComment #8
berdirThis is pathauto specific, the code is in AliasUniquifier::isRoute().
The exception that I added there is a workaround, previously it resulted in an endless loop. The problem is that if you have a route that's matching e.g. /article/example with a path like /article/{something}, then /article/example-0 will also match that route. And so on.
I'm not exactly sure what the difference is to 7.x. Maybe that only matched on exact path matches and didn't consider/support placeholders?
There is a possible overlap with placeholders, so it kind of makes sense to prevent that. But as explained above, our mechanism to find alternatives then fails, badly. So I'm not sure if we can get rid of that, or if we should consider to get rid of the check completely.
I think getting rid of it completely is risky. For example, if you use a top-level alias pattern, then there's a high risk to override core routes like /contact (there was a bug report on github from someone that was confused why his alias was set to contact-0 automatically). You risk making paths like /user inaccessible.
Comment #9
mstrelan commentedDrupal core already allows you to create a node with an alias of /user. Pathauto makes it easy to unwittingly create an alias of /user, if the node pattern is [node:title] for example and someone creates a node with "User" as the title. For sites with lots of content authors of varying levels of experience it makes sense to protect certain paths. This probably should be the site builder's responsibility. May I suggest a setting to disable these checks? Leave them as-is by default, but allow site builders to bypass this restriction.
Comment #10
GeoffGlasson commentedFirstly, thank you for your work on this module. It is very useful to me. I thought I might share my experience with this issue in the hope that it helps others and/or the developers figure out how to proceed.
I too have been having this issue and eventually found a workaround that appears to work for me. I was using the following pattern for blog entries
/blog/[node:title]
and was getting an error every time I added or modified a blog entry. Changing the pattern to
/blog/[node:created:html_year]/[node:title]
seems to have resolved the issue for me. I do have "Transliterate prior to creating alias" and "Reduce strings to letters and numbers" set, but these were set with the original pattern so I'm not sure if that make a difference.
I hope this helps
Comment #11
juampynr commentedHere is a comparison of how Drupal 7 and 8 + Pathauto deal with this:
Drupal 7
1. I create the following view to list articles at /articles with a term contexual filter such as articles/foo:

2. Pathauto has a pattern articles/[node:title] for articles.
3. I create a few article nodes.
4. I can Bulk Delete and Bulk Update aliases via Pathauto. The view works and nodes use the alias as expected.
Drupal 8
Steps 1 to 3 are the same as for Drupal 7. However, after bulk deleting aliases, I get the following error when I bulk update them:
Next steps
Given the above findings. I suggest that we remove that check in Pathauto so it works like the Drupal 7 version.
Comment #12
berdirIt's not as easy as just removing the check.
Drupal 7 has a check too. The problem is that menu_get_item('node/something') in D7 and \Drupal::service('router.no_access_checks')->match('/node/something') behave differently. In D7, that returns FALSE, in D8, it does match the existing route.
And the views case is additional complicated because I think views relies on the fact that in 7.x, any additional argument was automatically passed to the callback, even if you didn't specify any. So in 7.x, views registered just 'articles' for that path as the menu path, and in D8, it has to register /articles/{arg_0}.
so one thing we could try is only matching against fixed routes and ignore placeholders. I don't think there's an API for that, however. Maybe we can inspect the returned object and look if it has any slugs, or we could query the router table directly, if we have to.
Comment #13
juampynr commentedThis screenshot shows how the Drupal 7 version checks if a matching callback has a path or if it is a dynamic one:
We can do the same in the Drupal 8 version. Here is a patch. Let's see if the tests like it.
Comment #14
berdirSomething like that works for me, but lets add some comments why we're doing it like this. Tests would be great as well.
We don't have to use views and that complexity in the test I think, an example that uses node/[node:title] or something similar for users should be enough.
Comment #15
juampynr commentedI struggled to get a test to work using node/[node:title] as the pattern. Manually, I do get the error when I create a node, but the test behaves differently: it does not raise an error and instead it creates a weird alias. Therefore, I worked on another test using a view.
Here are four patches:
* use-node-path-2655873-15.patch is the patch that uses node/[node:title] and does not work.
* use-node-path-test-only-2655873-15.patch is the same patch but with just the test.
* use-test-view-2655874-15.patch uses a test view that simulates the scenario described at the top of the issue (a view with a contextual filter. This one works as expected and tests pass.
* use-test-view-test-only-2655874-15.patch is the same patch as above but without the fix. Fails as expected, showing the error reported in the issue.
I see value in having the test view here as it is the most realistic test scenario.
Comment #16
juampynr commentedSeems that the testbot was in Mallorca tanning and drinking a mojito. Re-uploading patches to see if it came back and is willing to test them now.
Comment #17
berdirTestbot just needed someone to give it a push now that the core issue got resolved. It still thought that our branch tests are failing and is waiting for them to pass again.
You can click on the patch files and click the button to force testing. I did requeue the branch tests now, so as soon as they come back green, it will run the tests.
Comment #18
berdirOr not, because the tests do not actually pass yet.
See https://www.drupal.org/pift-ci-job/183958.
The thing is that the url_alias table is now automatically created when accessed. But our custom query doesn't handle that yet.
Which is kinda fine (since there is no way that our code is called before alias storage can create it, except in kernel tests).
As a way to fix that, I'd say we just add a call to the alias storage service and e.g. call load(array()) with a comment in the failing test method. That will ensure the table exists. Can you open a separate issue for that?
Comment #37
berdirHa, testbot-spam.
Ok, I understand a bit better now.
My old example with /user/[user:name] or /node/[node:title] no longer works.
The reason is that core recently added validation for those that the value must be numeric. That's why a node title with "example" just works and with your example, it becomes node/1-0. That's exactly as expected. node/1 matches that route, then pathauto appends a -0 and tries again. And it no longer matches because that's not a number.
So this only still happens with slugs that do not have that numeric validation built in. Which is of course the case for something like views with arguments.
But I'm not 100% convinced anymore that we should just remove this kind of validation. IMHO, the use case from OP is kinda strange, Why would you want to use /articles/$category *and* /articles/$node-title exactly? Just like with the /user/login or similar examples, you get conflicts and will make it impossible to access a category view when you create an article with the same title.
Thoughts? We should definitely improve the error and make it clearer what's going on and explain how to avoid it, but it not be that stupid to disallow configurations like that?
Comment #38
juampynr commentedCool. This means that using the view in the test is now a good option, right?
Initially I felt like you. It seems wrong to use the same parent path for a pattern and a view as we are doing in the test. However, when I saw that this is supported in the Drupal 7 version I changed my mind. On top of that, this issue proves that site builders may want to do it. Therefore, I think that we should not worry about it and let them do it.
Comment #39
juampynr commentedTrying again.
Comment #42
juampynr commentedMy fix is causing an assertion in PathautoLocaleTest to fail. I will investigate further.
Comment #43
Saphyel commentedI bet the main reason is because the view /articles/ shows all articles, but he also wants to be able to filter them by category through the URL.
I personally think the approach of /articles/$category & /articles/$node-title is confusing... what happen if you have the category challenges and the article challenges ? drupal should show the view? the node? both? none? should avoid create that node? or the term?
I was thinking that maybe is better to move this to a views bugs.. because is more sensible use /articles/$vocabulary/$term or /articles/filter/$term rather than /articles/$term
Comment #44
juampynr commentedI just tested the following:
1. Uninstalled Pathauto.
2. Created a view with path '/articles' and added a contextual filter Term name so you can filter articles with tag 'foo' by opening '/articles/foo'.
3. Created an article with a custom alias such as '/articles/asdfasfafdfsda'. Core did not throw an error and created it.
Based on the above, I still think that we need to support this.
The matching route with the highest weight wins and processes the request.
Comment #45
Saphyel commentedso one of them will be block or inaccessible , right? so makes no sense have both of them if you won't be able to show both...
Comment #46
juampynr commentedThat's right. I would be surprised if this hasn't ever be discussed in the core issue queue.
Comment #47
mstrelan commentedOP here. The reason I would wanted to do this is because the site I was porting from D7 was configured that way. After reporting this I removed the argument from the articles view and I am using the core taxonomy/term/% page for the categories.
Comment #48
berdirSome inputs/thoughts
* That core allows to create such an alias is not really relevant. It also allows to create one for /user/login. There's no protection at all. But, the difference is that in core, you need to do it explicitly and are hopefully aware of the implications, while in pathauto, it happens automatically. you likely don't even see the alias field or know what kind of alias it's going to create.
* Note that this is not about route weight. One of those two things is an alias, the other is a route. Aliases are checked before routes, so the alias always "wins". routing is done on the system path.
* There is no "views" bug here, both things on their own work fine, you just can't combine them right now like that. You could easily create a view with a path "articles/by-category".
There's also the possibility of still allowing to check conflicts on a route like node/{node} by basically only ignore it if we get into the loop problem. But then we already have -0 in the alias, so that's not nice either.
Also here, I'd love to get input from dave. I don't really care that much, I just want to make sure that we fully understand the implications of whatever decision we pick. An updated issue summary that explains the exact behavior and pro/con of each option woud be great.
Comment #49
juampynr commentedHere is another patch that:
* Makes the message clearer by showing the route's path.
* Shows an alert instead of a PHP error.
* Implements a test.
This is what I see now when I create a node which has a pattern that collides with a view path:
And this is what I see when I do Bulk Generate:
Comment #50
berdirWhatever we decide here, we should definitely open a separate issue to catch exceptions in bulk generate and log/report them somehow at the end.
Comment #51
juampynr commentedCreated #2673234: Catch and list errors on Bulk Update
Comment #52
juampynr commentedRe-rolling #49.
@Berdir, do we still need @Dave Reid's feedback? Note that this patch respects the current implementation, where we maintain the current logic but we add tests and make the message more meaningful.
Comment #53
berdirOk, we can always make more changes, at least we have useful output now that tells users what's going on. We'll see if dave wants to do more and/or if we get new issues about this.
Comment #54
juampynr commentedMy patch at #52 improves the error message and adds testing coverage. Isn't that useful?
Comment #55
berdirForgot to push.
Comment #57
juampynr commentedYay!