First of all, this is a bug-report for awolfey regarding the new image_generate code supplied in #570834: Support for Devel Generate, which is neither a sub-module of image nor a stand-alone module yet (but will become one or the other at some point). When it does, this issue can be moved into the appropriate queue or updated with the correct component.

                                                        

When generating nodes which have a maximum number of images allowed, if the same image is selected by the random code and attempted to be used then we get duplicate key error messages for the image_attach table. To illustrate and reproduce this:

  1. Have a clean site with only one image node, see screen grab A
  2. Set the maximum number of images for a content type (eg story) to 10, to give a high chance that something higher than 1 is chosen at random
  3. Run devel_generate and create 1 story - get error messages in screen grab B
  4. The image_attach table has only 1 row - screen grab C
  5. The node only shows one image - screen grab D

The problem is that image_attach has a primary key of nid and iid, ie you cannot attach the same image node more than once. So in image_generate_nodeapi, when inserting rows into image_attach, I think you need to remove the used image from the $images array so that it cannot be randomly selected again. Also you then need to exit the loop if $images has now become empty, ie there are not enough distinct images to fill up to the randomly chosen limit.

Jonathan

Support from Acquia helps fund testing for Drupal Acquia logo