When saving a term I get the error user warning: Duplicate entry '17' for key 'PRIMARY' query: INSERT INTO taxonomy_title (tid, title) VALUES (17, '') in /.../taxonomy_title/taxonomy_title.module on line 161.. 17 is the tid of the term.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fuerst’s picture

Status: Active » Needs review
FileSize
591 bytes

Looks like an empty title will trigger the insert in _taxonomy_title_update(). As db_result() returns FALSE if no record found you can use that for triggering the update instead. Attached patch fixes that.

BTW: Wouldn't it be better to delete a record from {taxonomy_title} once a title gets empty?

jenlampton’s picture

Status: Needs review » Fixed

cleaning up queue

fuerst’s picture

Status: Fixed » Needs review

How did you fix the issue? Did not find a related commit. Therefore resetting status to the former one.

jenlampton’s picture

Version: 6.x-1.4 » 6.x-1.x-dev
Status: Needs review » Needs work

If you check the dev branch, there are already issets wrapped around the insert and update hooks that solve this problem. If you'd like to add a delete when title is empty though, I'll review that patch :)

joostpluijmers’s picture


Ah yea, those lines are probably the result of my overachieving IDE. The produced was:

user warning: Duplicate entry '2' for key 'PRIMARY' query: INSERT INTO taxonomy_title (tid, title) VALUES (2, '') in taxonomy_title.module on line 161.

This error occurred in the event that you edit a term with an empty title. The empty titles were caused by checking if a $form_state value was set, which it always is due to the form API. The update function checks against existence of a record which exists with an empty title string, but the check fails because an empty string is also false (go PHP freetyping ;). Thus causing the insert error.

I uploaded a new patch, with only the necessary lines. It also includes a ‘no query’ check by submitting an arbitrary flag that signals if there was a previous taxonomy title.

jenlampton’s picture

Status: Needs work » Needs review
FileSize
2.85 KB

Great work :)

I've cleaned up some of your syntax: changed true to TRUE and added/removed some spaces where necessary. See http://drupal.org/coding-standards for reference. Here's a new patch. Can you test this one and make sure it works the same as yours?

joostpluijmers’s picture

Thanks for the cleanup, I will have to outfit a formatter to match those coding standards and try out those development modules.

All mutations on terms and titles are working like in my patch. This works.

jenlampton’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! (In the future, you can also change the status of the issue when you leave your comment)

Do you feel up to providing a matching patch for the D7 branch? :)

jenlampton’s picture

Status: Reviewed & tested by the community » Fixed

committed to 6.x-1.x . will be included in the next release.

joostpluijmers’s picture

Then I am now officialy a Drupal contributor. :)

*Pops the cork*

jenlampton’s picture

Congratulations, and thank you! :)

Status: Fixed » Closed (fixed)

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