Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you have a taxonomy that is not required, no entry is selected by default (even if the user selected '' before). If the user submits now without reselecting the '' entry, a PHP warning like "Warning: Duplicate entry '38-50' for key 1 query: INSERT INTO term_node (nid, tid) VALUES (50, 38)" for each selected taxonomy term shows up.
This happens if you have at least two taxonomies on one node and the user selects something in one taxonomy list but leaves the other blank.
Comment | File | Size | Author |
---|---|---|---|
#14 | taxo_2.patch | 583 bytes | killes@www.drop.org |
#10 | taxonomy_27.patch | 2.28 KB | kkaefer |
#3 | taxonomy_26.patch | 2.17 KB | Zen |
Comments
Comment #1
Zen CreditAttribution: Zen commentedComment #2
nicklucas CreditAttribution: nicklucas commentedI attempted to recreate the scenario on my system. I'm running the latest cvs build as of Friday March 10, 2006 10:00AM PST, with PHP 4.4.1 and MySQL 5.0.18. I created 2 vocabularies with multiple terms and then created a page, selecting a term from one category but not the other. The page was created without any issues.
Comment #3
Zen CreditAttribution: Zen commentedThere are 2 issues here:
a) Primary issue: Taxonomy forms (or I believe any select form) with the multiple select option cannot have all their elements deselected, once they have already been set a value. i.e. select elements which have their existing selections deselected will revert to their default values. I believe the same issue cropped up with checkboxes as well, and should be related to the following block of code:
b) Immediate issue: Taxonomy forms for each vocabulary are set default values which also include terms from other vocabularies. So, due to the issue in a) when existing values for a vocabulary are deselected (i.e. there are no selections), the vocabulary reverts to its default values. These include values from other vocabularies as well and therefore trigger "duplicate" errors as the same term is saved twice (or more times). Patch attached. I've also added some minor formatting for some illegible (related) code.
-K
Comment #4
Zen CreditAttribution: Zen commentedComment #5
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedlooks good, can somebody test it?
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedi am still seeing the bug. i cannot clear the selections on a multiple select vocab
Comment #7
moshe weitzman CreditAttribution: moshe weitzman commentedComment #8
kkaefer CreditAttribution: kkaefer commentedPatch works for me. moshe: You can only clear the the selection if you don't have the required flag set on that vocabulary. However, if you have something selected and then select 'nothing' (not even '', the change is not saved. But if you select '', it works.
Comment #9
Zen CreditAttribution: Zen commented@Moshe: Yes, the patch only addresses the database error. The "clearing" issue needs to be fixed in form.inc. and is very likely applicable to all multi-select elements i.e. the attached patch only addresses part b.
-K
Comment #10
kkaefer CreditAttribution: kkaefer commentedPerhaps the '' value should be preselected - at least that's why it's there. I added this to Zen's patch. Three lines of code.
Comment #11
moshe weitzman CreditAttribution: moshe weitzman commentedworks for me
Comment #12
Zen CreditAttribution: Zen commentedI've created a separate issue for the forms bug.
Thanks for the reviews Moshe, timcn.
-K
Comment #13
Dries CreditAttribution: Dries commentedCommitted to HEAD. Great job guys! :)
Comment #14
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedZen told me that we don't need the code that timcn added. I propose to remove it.
Comment #15
Zen CreditAttribution: Zen commentedYep, selecting "none" by default etc. is unnecessary - it is there more to allow a user to "not select anything" than to tell the user that nothing has been selected. i.e. some end users might not be aware of "Ctrl + click" as an option to unselect an item.
I hadn't noticed that a different patch had gone through earlier - sorry about that.
Cheers,
-K
Comment #16
Zen CreditAttribution: Zen commentedRTC-ing. Patch still applies albeit with an offset.
-K
Comment #17
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedapplied
Comment #18
Zen CreditAttribution: Zen commented