pathauto tries to recreate existing alias
| Project: | Pathauto |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Hi,
we've chosen "Create a new alias. Leave the existing alias functioning" as update action. When we create a page, it gets its alias. Now we manually add an additional alias for this page because the page should have it's normal (pathauto created) alias and a shortcut for references.
When we edit the page again, pathauto only checks for *one* existing alias in _pathauto_existing_alias_data and finds the latest one, i.e. the manually added one. As this differs from the pathauto-generated one, pathauto tries to create a new alias and add it on every save of the node.
But as the pathauto-generated alias still exists, we get a error message "user warning: Duplicate entry..." on every save of the node.
I think that pathauto should fetch *all* existing aliases for a node in _pathauto_existing_alias_data and in _pathauto_set_alias() it should be sth. like
// Skip replacing the current alias with an identical alias
if (!in_array($dst, $old_alias)) {...Every other use of $old_alias would have to be changed to $old_alias[0].
What do you think about this? I could write a patch if you agree on this.

#1
Is nobody else getting this error?
#2
I suggest
1) Include the full error (and search for it). I've seen mentions of that error a lot. Inserting it here will help other people find this issue.
2) Provide a patch. If you have an idea of how to fix it a patch is always helpful.
#3
Ok, let me try...
When
then pathauto tries to recreate the formerly generated alias on every node save because it only compares it desired alias against the first existing alias it finds in the DB.
This leads to the error message
user warning: Duplicate entry 'test-' for key 2 query: INSERT INTO url_alias (src, dst, language) VALUES ('node/746', 'test', '') in /usr/share/drupal/modules/path/path.module on line 113.(here "test" is the pathauto alias).
Additionally, pathauto would only delete or redirect the first alias it finds in the DB and leave other existing aliases for a node unchanged.
The attached patch
_pathauto_existing_alias_datacollect all existing aliases (and their pids)_pathauto_set_aliascompares the new alias against all existing aliasesTo avoid breaking things I changed
_pathauto_set_aliasso that it can take either a single pid and single old_alias or arrays of both. Some of the patch is only for renaming $pid to $pids and $old_alias to $old_aliases.- hen creating an additional alias for pathauto-aliased node with settings "Create a new alias. Leave the existing alias functioning."
#4
#5
testing, I am getting this error in my logs on all submissions:
array_search() [<a href='function.array-search'>function.array-search</a>]: Wrong datatype for second argument in /home/alipaz3/public_html/cbbeta/sites/all/modules/pathauto/pathauto.inc on line 402.Also, does not seem to fix any of the issues.
#6
What version are you testing against exactly (-dev 1.x from which day)?
Also, what do you mean by "any of the issues"? It should fix only one issue, i.e., preventing the re-recreation of an existing alias.
#7
Got the datatype errors, that was due to pre-initializing with NULL instead of array(). Thanks for spotting this!
Could you try the new patch?
#8
Updated to include the fix against unintended alias removals, see http://drupal.org/node/388626
Since the multiple_alias patch changes the case distinctions when to call path_set_alias with which parameters, the anti-removal fix looks a bit different here, so I included it. As deletion and redirection is done within a different if-case now, we just need to prevent calling path_set_alias if $dst is empty.
#9
not sure if related.. possibly not, but i get same error on every node save, but my settings are: Create a new alias. Delete the old alias.
and error is:
user warning: Duplicate entry 'journal/roto-wisi-' for key 2 query: UPDATE url_alias SET src = 'node/44', dst = 'journal/roto-wisi', language = '' WHERE pid = 114 in C:\Inetpub\websites\8to13\modules\path\path.module on line 100.
although, just noticed, possibly related to items with common titles and the -n at end of url - these were auto-created test nodes from the devel module
115 node/44 journal/roto-wisi116 node/44/feed journal/roto-wisi/feed
117 node/45 node-45-journal
118 node/45 journal/roto-wisi-0
119 node/45/feed journal/roto-wisi-0/feed
120 node/46 node-46-journal
121 node/46 journal/roto-wisi-1
122 node/46/feed journal/roto-wisi-1/feed
123 node/47 node-47-journal
124 node/47 journal/roto-wisi-2
#10
It is related. pathauto will only delete *one arbitrary* old alias. So if you have two aliases (like for node/45 etc. in your case) and pathauto does not delete the one it tries to create, you will exactly run into this situation.
The patch should help here. Could you test it and report how it works for you?
#11
applied pathauto_multiple_aliases_v3.patch and it worked well for me when dealing with a situation much as described in comment # 3 -- thanks!
#12
@Frank Steiner - thanks so much for your work troubleshooting and fixing this. I had never run into it before and now I see what the problem is. It won't show up for most people, but for those where it does...boy is it annoying.
Does this issue affect 5.x as well? If so, can you roll a patch for 5.x as well? If you don't use 5.x then that's OK, I can try to do it.
#13
I've never used Drupal 5.x so I guess I'm not a big help here :-) But I will at least try to port the patch for the -2.x branch, too, ok?
#14
Here are versions for the latests -dev releases for -1.x and -2.x, including the patch from http://drupal.org/node/388626
#15
Hmm, is there anything else I can do to get these patches applied to the -dev versions?
#16
Hi Frank - if you could write simpletests for it that would absolutely help. There is a basic simpletest file in Pathauto now which should make it easier to learn.
Otherwise, I just need some time to sit down and review it.
#18
Ok, I've no idea what simpletests are yet, but I will learn and try to do it :-)
#19
I've applied the patch pathauto_multiple_aliases_v4.patch from #14 in a situation similar to the one described in #9, and it works great ! Thanks !
@Frank Steiner: Do you want/need help for the testing part of this patch ?
#20
Would be nice, yes, because I haven't yet looked into the simpletest stuff, so I still don't even know what I would have to do :-D I simply don't have enough time at the moment as we are upgrading our whole chair from SLES 10 to SLES 11. So whatever you can/want to do get this started will be appreciated! You can also contact me directly.
#21
Ok, first stab at a patch for adding a test for this issue. It's only the test part, which highlights the fact that there's one test fail as is, and that it disapears when the patch from #14 is applied.
While a bit contrived, the test in the example is one of the most reliable ways to introduce the inconsistency which leads to the warning this bug deals with.
#22
@ #12 greggles
Hi greggles,
No this isn't an issue in 5.x (specifically Pathauto 5.x-2.0-beta2). One of the sites we do is currently stuck on 5.x due to other module upgrade problems, it has hundreds of nodes with multiple pathauto aliases, with the odd node having 5+ aliases. (Client started out with static html files, converted to ??, converted to D4, ...)
We can confirm Pathauto 6.x-1.2 (D6.14) is deleting all other (even manually added) aliases upon a node edit as identified by Frank. I'll apply the patch(es) to a test site and see if I can break 'em.
Will take a couple weeks,
Sam
PS: Somewhat curious why we can't just rip the 5.x code in the offending section? Guess I'll look at that too
PS2: Congrats on a great module, where beta-2 is still in production (no don't ask, clients are clients)