path_set_alias() doesn't account for same alias in different languages

Steve Dondley - June 12, 2008 - 17:34
Project:Drupal
Version:6.x-dev
Component:path.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:patch (code needs work)
Description

    * user warning: Duplicate entry 'about-first-trade-union-bank-' for key 2 query: INSERT INTO url_alias (src, dst, language) VALUES ('node/7', 'about-first-trade-union-bank', '') in /home/unionsites/d6_public_html/modules/path/path.module on line 112.
    * user warning: Duplicate entry 'about-first-trade-union-bank/feed-' for key 2 query: INSERT INTO url_alias (src, dst, language) VALUES ('node/7/feed', 'about-first-trade-union-bank/feed', '') in /home/unionsites/d6_public_html/modules/path/path.module on line 112.

#1

greggles - June 13, 2008 - 07:03
Status:active» active (needs more info)

Do you have any steps for how to repeat this?

#2

Steve Dondley - June 13, 2008 - 07:06

No, just started happening.

#3

greggles - June 13, 2008 - 07:07

Well, I've never seen this and nobody else has reported it. For now it seems to be specific to your site. It seems quite likely that it's a bug in Pathauto, but I don't know how to repeat it so I can't debug/fix it...

#4

Freso - June 13, 2008 - 08:16

@Steve Dondley: What other modules are you using?

#5

xanga2008 - June 19, 2008 - 20:23

Im also facing the similar issue.

it started after i have installed the latest category module.

user warning: Duplicate entry 'node/-' for key 2 query: INSERT INTO url_alias (src, dst, language) VALUES ('taxonomy/term/30', 'node/', '')

Is this is a critical bug, should i uninstall category module?

#6

greggles - June 19, 2008 - 20:33
Project:Pathauto» Category
Version:6.x-1.0» 6.x-2.0-alpha1
Status:active (needs more info)» active

it started after i have installed the latest category module.

That explains it a bit...

#7

kees@qrios - July 18, 2008 - 12:04
Project:Category» Drupal
Version:6.x-2.0-alpha1» 6.3
Component:Code» path.module

Hi,

I have the same issue (I believe).

Message:


user warning: Duplicate entry 'title/feed-nl' for key 2 query: INSERT INTO url_alias (src, dst, language) VALUES ('node/7/feed', 'title/feed', 'nl') in absolutepath/modules/path/path.module on line 112.

In my opinion it is a combination of pathauto and the in core content translation modules.
I don't have categories module installed.

In my case the system tries to generate duplicate aliasses for content submissions (and feeds) with different languages and the same node title.

In pathauto I do not have language specific settings.

At this point I am not sure, it could be 'old' aliasses not deleted from nodes that have a language change, title change or deleted content aliases.

I've seen 3 or 4 of these messages, I'l try to report here if this happens more often.

Kees

#8

kees@qrios - July 18, 2008 - 12:07
Component:path.module» translation.module

If someone has a better clue wich project/component is responsible, please shift.

#9

John.Mulder - July 27, 2008 - 12:01

I'm having exactly the same issue here. Working local with the taxonomy module. The error occurs when I save an edit of an entry in a vocabulary. Despite the warning, the entry is updated and saved however. Below te warning I get:

user warning: Duplicate entry 'taxonomy/term/7-' for key 2 query: INSERT INTO url_alias (src, dst, language) VALUES ('taxonomy/term/', 'taxonomy/term/7', '') in G:\Server\xampp\htdocs\private\drupal\modules\path\path.module on line 112.

#10

greggles - July 27, 2008 - 13:09
Project:Drupal» Category
Version:6.3» 6.x-2.0-alpha3
Component:translation.module» Wrapper modules

@qrios, @john.mulder - do you use the Category module?

This is an issue with the Category module, afaik.

#11

John.Mulder - July 27, 2008 - 17:44

No, I'm not using the Category module. My feel is that there's a flaw with the check on whether an entry already exists, as the path.module obviously tries to enter something in the db that already is there.

Tnx for your contribution.
John

#12

greggles - July 27, 2008 - 19:13
Project:Category» Pathauto
Version:6.x-2.0-alpha3» 6.x-1.x-dev
Component:Wrapper modules» Code
Status:active» active (needs more info)

Great - thanks for the quick response. So...let's bring this back to Pathauto then ;)

@John.Mulder - Which version of Pathauto are you using and what are the steps you take to get this error to happen?

#13

Steve Dondley - July 27, 2008 - 19:20

I am not using the category module.

#14

John.Mulder - July 28, 2008 - 20:02

Hi Greggles,

I'm using the latest version: 6.3. I just discovered that the warning does NOT occur if I uncheck the 'Automatic alias' checkbox which I find quite near the bottom of any page for editing a node. It is definitely a path module issue. I have just made some changes in a form created using the latest version of the webform module. It is exactly the same error as with the previously mentioned Taxonomy edit.

So basically this is my situation: I have url rewrite enabled and thus the path module so as to have nicely readable url's; they make me happy ;)

For any content I am editing (except when editing a blog entry or a story entry) I get the mentioned error/warning upon saving/submitting the edit. The only way to avoid it, is by unchecking the checkbox 'Automatic alias' and then submitting the changes. @steve: can you confirm this?

Tnx for your help.

Cheers,
John

#15

Steve Dondley - July 28, 2008 - 20:33

Yes, this is the behavior I'm seeing. I only get the error when submitting content. I do not get an error when automatic alias is unchecked.

#16

Steve Dondley - July 28, 2008 - 20:38

I looked at the other modules, there is no other that I have that I think could affect pathauto. Non-core modules are:

admin menu
image
fckeditor
nice menus
token
webform
views
view ui

BTW, I have about 5 other very lightly used drupal 6 site but have not seen this problem. But those sites are not administered much.

#17

greggles - July 28, 2008 - 21:55

Ok - thanks for the additional information. I still haven't seen this bug and, as Steve Dondley says, it's not consistent across his sites. If you do find more information on what is causing this please let me know.

One other question (though it may not matter) are you sure you've you're running the latest version of token and that run update.php since updating Token/Pathauto?

#18

kees@qrios - July 29, 2008 - 07:20

@qrios, @john.mulder - do you use the Category module?

No, Im not.

#19

Steve Dondley - July 29, 2008 - 16:25

Everything is up to date.

#20

John.Mulder - July 29, 2008 - 19:35

Everything up to date here also.

Token 6.x-1.10
Webform 6.x-2.1.2

And again: not using the category module.

I may have found part of the cause. In the path module under Automated Alias Settings, there's a text area filled with small words (like in, with, and etc.) that are supposed to be filtered from a url-alias.

When editing a post, one seems to be able to fill in any of those words again, by unchecking the earlier mentioned Automatic alias checkbox . In my case: /getting-in-touch would automatically become /getting-touch when left to the automatic aliasing mechanism. This is somewhat awkward, so I changed it back to /getting-in-touch manually. At that point there seems to be a conflict with the Automated Alias Settings of the path module, as soon as one edits a node again and submitting the changes with the Automatic alias checkbox checked.

Hmm, quite a story huh ;) Hope this still makes some sense. Again: it is definitely a bug, but not very major. My guess is it's a flaw in the logic behind the path module: user and system are allowed to perform contradictory actions. That would confuse me too ;)

Cheers,
John

#21

Steve Dondley - July 29, 2008 - 20:15

Everything is up to date.

#22

nonsie - August 7, 2008 - 17:38

I haven't encountered this error until the current site I'm working on.

One thing I've noticed is that when a translation is created and the alias is exactly the same as for the original node the alias for translated node is not changed to alias-0. So after translating the node original node and translated node will end up having the same alias triggering an error each time original or translated node is updated. I'm pretty sure the problem lies in the combination of content translation and pathauto but not quite sure where.

#23

greggles - August 7, 2008 - 18:46

Is everyone else having this problem using content translation module?

#24

Steve Dondley - August 9, 2008 - 04:28

I'm not using the translation module.

#25

Freso - August 9, 2008 - 06:26

@Steve Dondley (and everyone else answering #23):
How about the Locale module?

#26

Steve Dondley - August 9, 2008 - 15:02

No, locale module either.

#27

kees@qrios - August 11, 2008 - 08:00

"Is everyone else havig this problem using content translation module?"

Yes I am. See post #7, I think it's related to translated content with same node title, since that's gonna be my URL alias. E.g. "Contact" is a common node title for the contact page in many languages. But looking at the other posts, this is not the only scenario triggering this error.

More specific:
I use locale.module and parts of i18n.module for block- and string translation only.

#28

nonsie - August 11, 2008 - 17:27

I think I'm starting to get it - looking at query log and it's core path module that's causing the issue.
I have pathauto set up to use titles for aliases, I've created a node titled foobar in English and translated it into Spanish. I can create both nodes without any errors.
However I'm getting an error on node update:
UPDATE url_alias SET src = 'node/359', dst = 'foobar', language = 'en' WHERE dst = 'foobar'

Looking at path_set_alias() function it does not account for same alias in different languages, dst is not an unique field - if both dst and src are set the following part of the function is executed:

if ($alias == drupal_get_path_alias($path, $language)) {
      // There is already such an alias, neutral or in this language.
      // Update the alias based on alias; setting the language if not yet done.
      db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE dst = '%s'", $path, $alias, $language, $alias);
    }

In my case I have two aliases named 'foobar' in two different languages causing the update to error.

Any ideas how to fix this?

#29

Freso - August 11, 2008 - 17:42
Title:mysql errors when saving a page» path_set_alias() doesn't account for same alias in different languages
Project:Pathauto» Drupal
Version:6.x-1.x-dev» 6.x-dev
Component:Code» path.module
Status:active (needs more info)» active

Well, path_set_alias() obviously needs to take account of the language when setting the alias. And this needs to happen in core, as the problem (if I understand correctly from the above mentions) should be reproducible on non-Pathauto setups as well. (Do move back if that is not the case though.)

I'm thinking that y'all might not be having the same issue, even if the symptom is the same. If core's path.module can be fixed (if it is indeed broken) and make one of the issues go away, we'll hopefully be better able to "treat" the rest. :)

#30

nonsie - August 13, 2008 - 18:13
Status:active» patch (code needs review)

Attached patch fixes part of the problem - setting correct language alias for nodes. Still looking into taxonomy duplicate alias issue.

AttachmentSize
path.module-path-set-alias.patch1.06 KB

#31

scottrigby - August 15, 2008 - 14:52

I'm seeing the same error in a D6.4 installation:

user warning: Duplicate entry 'adverts/faq-' for key 2 query: INSERT INTO url_alias (src, dst, language) VALUES ('node/6', 'adverts/faq', '') in /home/archiveo/public_html/modules/path/path.module on line 112.

My pathauto's Automated Alias Settings
* General Settings > Update Actions: 'Create a new alias. Leave the existing alias functioning.'
* Node Path Settings > Pattern for all Image paths: 'adverts/[title-raw]'

What's happening in my case
* On certain nodes of that type (in this case the type is image) I had already set the path alias to be different (this is because there are a few images on our site that are not 'adverts' but the rest are... hence adding that path logic mentioned above.
* But based on the error, it seems that when I edit these nodes, pathauto adds a new alias based on the logic, while also keeping the old one.

Module info:
* I don't have Category module installed, or core Taxonomy module enabled.
* using pathauto-6.x-1.1
* token-6.x-1.11
* cck-6.x-2.0-rc4
* globalredirect-6.x-1.0
* stringoverrides-6.x-1.6
* xmlsitemap-6.x-0.x-dev
(I have other mods installed like image, etc, but i'm not sure how many of these are relevant)

Hope this provides more info?

:) Scott

#32

nonsie - August 15, 2008 - 19:18

does the patch in #30 remove the error for nodes?

#33

scottrigby - August 15, 2008 - 22:05

hi nonsie,
I tried to apply the patch, but it failed. So I looked to see if the core path module changed between D6.3 and 6.4. – and apparently it did...

#34

Freso - August 15, 2008 - 22:55

Edit: Err, wait. Hang on. Sorry. That was for another issue. Please disregard me. :$ Is it an okay excuse that it's 10 to 1 AM? >_>

#35

nonsie - August 16, 2008 - 00:25

hmm, I don't think there were any changes in path.module in 6.4 (at least they are not in the patch file)

#36

scottrigby - August 16, 2008 - 05:21

omigosh. Ok, apparently I must have been hallucinating from sleep dep...
nonsie you are so right about that (the mod did NOT change between 6.3 & 6.4...) – what I did was a diff on a D5 installation by mistake!

Ok, so I applied the patch (which DID successfully patch), and I replaced the core path module with the patched one...

However, I still get the errors, like:

    * user warning: Duplicate entry 'reviews/put-your-crazy-pants-lets-party-' for key 2 query: INSERT INTO url_alias (src, dst, language) VALUES ('node/28', 'reviews/put-your-crazy-pants-lets-party', '') in /home/archiveo/public_html/modules/path/path.module on line 117.
    * user warning: Duplicate entry 'reviews/put-your-crazy-pants-lets-party/feed-' for key 2 query: INSERT INTO url_alias (src, dst, language) VALUES ('node/28/feed', 'reviews/put-your-crazy-pants-lets-party/feed', '') in /home/archiveo/public_html/modules/path/path.module on line 117.

Do you think it's because there are already dupes in the table? If so, how should I go about getting rid of these?

Otherwise I'm not sure how to test, because I still get errors even after the patch...

One other thought... should I run the update script now that the module has been modified?

#37

waynef100 - August 21, 2008 - 16:39

the solution for me was to look inside the url_alias table. i found the duplicate src entries and verified they werent being listed in the admin > site building > url aliases page. i removed the invalid aliases from the table manually. For me this is only an issue on some pages so I have just been doing these steps as the errors occur.

also i had previously enabled language support but then disabled it. i had to then go and clear all the language settings from the url_alias table

#38

kees@qrios - August 22, 2008 - 09:56

"One other thought... should I run the update script now that the module has been modified?"

Cant hurt. Basically it executes update code in the install script of an updated module if available, and clears cache.
Since the patch doesn't effect the install script it should not be necessary.

#39

Alauddin - September 10, 2008 - 12:46

I just changed my url alias setting to get rid to this error.

Admin > Site building > Url Alias > Automated Alias Setting > General Setting
under 'update action'
select : Do nothing. Leave the old alias intact.

The only reason I had it on - Create a new alias. Leave the existing alias functioning - was because I am working on a new site and wanted to have the urls update.

In general I think it is BEST to leave setting at : Do nothing, leave the old alias intact
for these 2 MAIN reasons
1) no broken links. If your page was indexed and you now 'updated' the url - users get 404 error on the old url indexed by SE
2) all your hard work to 'optimize' pages and have them indexed by SE's goes to waste if you just 'update' the url.

ps: if you do must update urls - then consider '.htaccess' 302 redirects of old urls to new to keep from having 404 errors

#40

nonsie - September 10, 2008 - 16:25

Setting update action to "Do nothing" doesn't solve the issue itself - you still won't be able to have same alias in multiple languages.

#41

earnie - September 10, 2008 - 20:57
Status:patch (code needs review)» patch (code needs work)

Wouldn't the correct fix for

Duplicate entry 'reviews/put-your-crazy-pants-lets-party-' for key 2 query

be an addition to the dst key of the language column? But system_update_6005() is supposed to do that already. Did your update add create a new dst unique index with the language column like it should have?

Also, I notice that

VALUES ('node/28', 'reviews/put-your-crazy-pants-lets-party', '')

from #36 has an empty language column.

I agree that the correct action for pathauto users is as Alauddin explains in #39.

The patch needs work because it only needs to exchange the update with

<?php
+        db_query("UPDATE {url_alias} SET src = '%s', dst = '%s' WHERE dst = '%s' AND language = '%s'", $path, $alias, $alias, $language);
?>

It doesn't need to test if $language is set.

You probably should roll the patch for D7 first and then it can be back ported to D6

#42

nonsie - September 10, 2008 - 21:56

system_update_6005 did create new unique index - UNIQUE KEY `dst_language` (`dst`,`language`).

The patch also needs to check if $language exists. For example let's say a user created a node in English and saved it. Later, the user went back and changed the node language setting to no language - in that case your update would fail because $language is not set yet in the database it's set to en.

#43

earnie - September 11, 2008 - 10:52

The patch also needs to check if $language exists. For example let's say a user created a node in English and saved it. Later, the user went back and changed the node language setting to no language - in that case your update would fail because $language is not set yet in the database it's set to en.

The example you give should never exist. The alias doesn't exist so an insert would happen. If this code is executed without a record being available to update; then we have a bug somewhere else. There is no need to filter the update based on $language.

#44

nonsie - September 11, 2008 - 16:43

Earnie, you are right - an insert would need to happen rather than update however at the moment it doesn't.
I'm not quite sure what's the policy re keeping old aliases eg in the example I provided you would have one alias with language set to en and one set to blank rather than updating the old en language alias?

#45

earnie - September 11, 2008 - 18:30

IMO, an alias of $language = '' and one of $language = 'en' are different aliases even though the result is the same. One might argue that $language = '' is assuming a default and it should be set to the specified default before saving to the db.

<?php
if (empty($language)) {
 
$language = variable_get('default_language', 'en');
}
?>

#46

nonsie - September 11, 2008 - 21:23

No language is not the same as default language - if it was it would require major rewrite of all modules that implement that.

So we have established that path module should create a new alias record if alias/language is changed, which means that the problem is in drupal_get_path_alias

#47

earnie - September 11, 2008 - 22:02

I don't think so. If a user creates an alias with a language set and then set no language the appropriate action is a warning that the language dependent data will not be active. It is then up to the user to update the nodes for which she wants aliases for the no language setting. A contrib module in the development package could be added to translate the language specific items to no language items. It shouldn't be up to Drupal core to clean up the mess.

However, your patch points out a defect in the update because the language key should be specified in the WHERE clause.

#48

Manuel Garcia - September 16, 2008 - 11:51

Also having this issue, subscribing

#49

kesmeby - October 1, 2008 - 13:45

This is the error I'm getting after saving content with Path Auto enabled:

user warning: Duplicate entry '/feed-' for key 2 query: UPDATE url_alias SET src = 'node/1/feed', dst = '/feed', language = '' WHERE pid = 5 in /home/kyle/public_html/chsfsalpha/modules/path/path.module on line 100.

For some reason PathAuto is creating a duplicate of each node with "/feed" appended to the end. I'm not using any language features or trying to publish RSS of the site.

#50

greggles - October 1, 2008 - 14:44

@ksemeby - the symptom is similar, but the underlying problem you have is different. Please create a new issue in the Pathauto issue queue about your problem.

 
 

Drupal is a registered trademark of Dries Buytaert.