Once i update a product kit i get the following error:
user warning: Duplicate entry '8' for key 'PRIMARY' query: INSERT INTO uc_products (vid, nid, model, list_price, cost, sell_price, weight, weight_units, default_qty, unique_hash, ordering, shippable) VALUES (8, 8, 'asdsddad / IT123123012983 1', 1.4, 0, 2.8, 0, 'lb', 0, '44f7981e0e139c061c789c94093cced8', 0, 0) in /Volumes/SG/httpdocs/drupal/sites/all/modules/ubercart/uc_product_kit/uc_product_kit.module on line 351.
and even though it's a warning the update dot not take place anyway.
btw how came an update is performed doing and INSERT INTO instead of an UPDATE SET..?
Comment | File | Size | Author |
---|---|---|---|
#14 | PK_dup_ents-641430.patch | 2.02 KB | griz |
#4 | duplicate_entry.png | 166.86 KB | randallpena |
Comments
Comment #1
TR CreditAttribution: TR commentedWhat do you mean by "update a product kit" ? What exactly are you doing when you get that error? Does it happen for all product kits or just one?
Line 351 in uc_product_kit.module is a blank line in Ubercart 6.x-2.2 - are you sure you are using 2.2 and have an unaltered version of the uc_product_kit.module code? That INSERT statement appears on lines 333 and 343. To me it sounds like you have added code or are using an old version, in which case the first thing you should do is make sure you have a clean unmodified version of uc_product_kit then test for the error again.
You ask: "how came an update is performed doing and INSERT INTO instead of an UPDATE SET..?". If you look at the code, you will see an UPDATE is attempted, then if and only if no rows were affected an INSERT is used to add the data to the table.
Comment #2
TR CreditAttribution: TR commentedTagging
Comment #3
redamo CreditAttribution: redamo commentedI too get the following error when trying to edit a product kit. (for instance when promoting on first page.)
user warning: Duplicate entry '167' for key 'PRIMARY' query: INSERT INTO uc_products (vid, nid, model, list_price, cost, sell_price, weight, weight_units, default_qty, unique_hash, ordering, shippable) VALUES (167, 167, 'Any / Any / Any / Any / Any / Any / Any / Any / Any / Any', 0, 0, 99.99, 0, 'lb', 0, '1d6ad7a5ac8612d15785bbcfe92b7c4d', 0, 0) in /usr/home/redamo/drupal-6.19/modules/ubercart/uc_product_kit/uc_product_kit.module on line 313.
Comment #4
randallpena CreditAttribution: randallpena commentedI'm also getting this error. Here is how I am able to replicate the error:
1. create a product
a. Name: iPod Nano
b. SKU: AL-123-00001
c. Sell Price: 199.99
d. Attached 5 images
2. create another product
a. Name: iPod Sync Cable
b. SKU: AL-123-00002
c. Sell Price: 0.00
3. create a product kit
a. Name: iPod Nano package
b. As a unit. Customers may only change how many kits they are buying. Do not list component products
c. Total price is blank
d. Products: ipod Nano, iPod Sync Cable
e. After saving, try to update any value of this product kit (e.g. description). You will get the following error message attached.
I am simply following the instructions in chapter 4 of the book "Drupal e-commerce with ubercart 2.x"
Let me know if you need more info. Thanks!
Comment #5
randallpena CreditAttribution: randallpena commentedComment #6
horuskol CreditAttribution: horuskol commentedI get this with the 6.x-2.4 release when I'm doing something like changing the image or description of the Product Kit.
As I read this - the problem is that I'm not changing any of those fields in the update query (although, I am changing something about the Product Kit itself) - so db_affected_rows will return 0, causing the insert to be attempted.
Also - since db_affected_rows can also return -1 for error, the insert will NOT be attempted if there was an error in the update query (not sure if this was intentional).
Unfortunately, the only way to get the number of matched rows for an update query through the PHP/MySQL library is to pass a flag when opening the db connection - which would affect all instances of db_affected_rows.
The only thing I can think of is to replace the queries with a single REPLACE - although, that is not a standard SQL query - or we perform a SELECT first to determine if the UPDATE or INSERT is required.
Comment #7
horuskol CreditAttribution: horuskol commentedThis seems to do the trick:
Comment #8
longwaveLong SQL statements like that are ugly and hard to maintain; we should switch to drupal_write_record() if at all possible.
Comment #9
tomotomo CreditAttribution: tomotomo commentedI also see this when calling uc_product_insert($node)
Comment #10
jlporter CreditAttribution: jlporter commentedI also have this issue on a new 2.4 install. Only edit an arbitrary attribute and get duplicate key warning, it does seem to save the parts I'm concerned about though.
user warning: Duplicate entry '133' for key 'PRIMARY' query: INSERT INTO uc_products (vid, nid, model, list_price, cost, sell_price, weight, weight_units, default_qty, unique_hash, ordering, shippable) VALUES (133, 133, 'autographed-cd / hatch / bottle-opener', 0, 0, 29.99, 0, 'oz', 0, '1f0a3370cb0a0fc890a42a4e99fccf13', 0, 1) in /mnt/www/retreat.craigcampbell.tv/site/sites/all/modules/ubercart/uc_product_kit/uc_product_kit.module on line 313.
Comment #11
armetrix CreditAttribution: armetrix commentedThanks for your input on this chronic problem. Just where exactly did you place this code? I've attempted to use it a few times and I continue to get the error saying duplicate entry.
Comment #12
horuskol CreditAttribution: horuskol commented/sites/all/modules/ubercart/uc_product_kit/uc_product_kit.module on line 351 < somewhere about there
Comment #13
TR CreditAttribution: TR commentedCan you post a real patch?
Comment #14
griz CreditAttribution: griz commentedReviewed and tested by me. Anyone else?
Comment #16
TR CreditAttribution: TR commented(Patch looks fine - testbot complains about everything when the issue version is a fixed point release like 6.x-2.4).
Comment #17
griz CreditAttribution: griz commentedThanks for the explanation. Git is still something of an enigma to me. What is the next step?
I've altered the dev version for my own site, but I got that through drush. How do you get dev through git?
Alternatively, can I make a diff that will pass testing without using git?
Sorry for the 20 Qs.
Comment #18
TR CreditAttribution: TR commentedNext step is to wait for someone other than you to verify that the patch works to fix the problem. Hopefully one of the seven people who posted above that they are experiencing the problem can tell us whether your patch fixes the issue. If it does, I'll commit it.
To use git to keep up with the latest version of -dev:
git clone git://git.drupal.org/project/ubercart.git
cd ubercart
git checkout 6.x-2.x
then occasionally
git pull
to get the changes that have been made in the repository and merge them into your private copy.
git status will show you any changes you've made locally that differ from what's in the repository, and git diff will generate a diff file of those differences which can be used as a patch.
That's the basics - lots of help is available on #drupal-gitsupport, feel free to ask even the most elementary git question.
Comment #19
horuskol CreditAttribution: horuskol commentedHi - sorry for the long gap in responses from me on this issue. I've been distracted by other projects, and then this issue stopped being a problem for me as we implemented a workflow that forces new revisions and so bypassed the bug.
Anyway - I've just tested the patch, and confirm that it resolves the original reported issue when saving products and product kits.
Thanks for your help and effort
Comment #20
longwaveSuspect that the suggested fix will only work on MySQL due to the way db_affected_rows() works:
http://api.drupal.org/api/drupal/includes--database.pgsql.inc/function/d...
Comment #21
longwaveComment #22
melon CreditAttribution: melon commentedI just stumbled upon this issue as this is the first time I need product kits.
The patch in #14 works nice for me as well with MySQL.
Comment #23
TR CreditAttribution: TR commentedMoving to "Product kit" component.
Comment #24
TR CreditAttribution: TR commentedNow that the testbot is finally working, let's see if it likes the patch.
Comment #25
TR CreditAttribution: TR commented#14: PK_dup_ents-641430.patch queued for re-testing.
Comment #26
longwaveThe correct pattern for this is just to prefix the insert query with @ according to #805858-3: Affected rows inconsistent across database engines
Fixed in http://drupalcode.org/project/ubercart.git/commitdiff/dfe8b96