Getting a PDOException when adding new image style named thumbnail, medium and large

Created on 8 August 2013, over 11 years ago
Updated 26 May 2023, over 1 year ago

When adding a new image style and a custom image_style with that name allready exists, this error message appears 'The machine-readable name is already in use. It must be unique.' Nice.

But when adding a new image style named thumbnail, medium or large, you will get a PDOException.
Only happens when the image style is allready overridden.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'medium' for key 'name': INSERT INTO {image_styles} (name, label) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => medium [:db_insert_placeholder_1] => Medium ) in drupal_write_record() (line 7166 of /../../vhosts/drupal/dev/includes/common.inc).

🐛 Bug report
Status

Fixed

Version

7.0 ⚰️

Component
Image module 

Last updated 5 days ago

Created by

🇳🇱Netherlands zwikzwik

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.4 & SQLite 3.27
    last update over 1 year ago
    2,145 pass
  • 🇸🇰Slovakia poker10

    Adding a tag for the feedback from other maintainer.

  • 🇬🇧United Kingdom mcdruid 🇬🇧🇪🇺

    Perhaps I'm missing something, but isn't passing all of the constants in the $include param the same as not passing it at all?

    I think this patch would most likely be fine to commit, but I don't think the $include param is doing anything as it stands so it might as well be omitted?

    I'm also being slightly distracted by the fact that the docblock seems to be quite wrong / outdated; it doesn't mention that $include can be a bitmask and it says it'll return an empty array if the style's not valid but it actually returns FALSE.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.4 & SQLite 3.27
    last update over 1 year ago
    2,147 pass
  • 🇸🇰Slovakia poker10

    I'm also being slightly distracted by the fact that the docblock seems to be quite wrong / outdated; ... it says it'll return an empty array if the style's not valid but it actually returns FALSE.

    Yes, this is interesting. Looking at other functions calling image_style_load(), it seems like most of them expects an array (like the documentation mentions), and not doing some extra checks. I tried to check the issue queue, if there is any complaint about this from the past, but was not able to find anything.

    it doesn't mention that $include can be a bitmask

    I think I figured it this out only when looked at the constants definition (when working on patch #15):

    /**
     * Image style constant to represent an editable preset.
     */
    define('IMAGE_STORAGE_EDITABLE', IMAGE_STORAGE_NORMAL | IMAGE_STORAGE_OVERRIDE);
    
    Perhaps I'm missing something, but isn't passing all of the constants in the $include param the same as not passing it at all?

    This is true, it seems like I have missed this. I can update the patch to remove the constants, but the main question is, do we want to get with the safer approach (patch #9, which will fix the error, but does not touch the situation, when it is possible to silently override the default style by creating a new with the same name) or we will use the more complex approach (patch #15, which will check also not-overriden styles). If we choose the more complex approach, it would probably be better to mention this at least in release notes, as this seems like a bug, but we are introducing a slight change in the behavior (though I am not sure if this can have a usefull use-case).

    So I will update the patch #15 or #9, according to the decision. Thanks!

  • 🇬🇧United Kingdom mcdruid 🇬🇧🇪🇺

    I think let's try with simply:

    +/**
    + * Check if the proposed machine name is already taken.
    + */
    +function image_style_add_form_name_exists($name) {
    +  return (bool) image_style_load($name);
    +}
    

    The new test passes for me locally with this, but would be good to check the rest of the test suite.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    2,151 pass
  • 🇸🇰Slovakia poker10

    Updated the patch. I am not uploading a test-only patch, as the tests have not changed (so the one from #15 is still the same).

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.4 & SQLite 3.27
    last update over 1 year ago
    2,147 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    2,151 pass
  • last update over 1 year ago
    2,151 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.4 & PostgreSQL 9.5
    last update over 1 year ago
    2,112 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 5.3 & MySQL 5.5
    last update over 1 year ago
    2,151 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    run-tests.sh exception
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.2 & MySQL 5.6
    last update over 1 year ago
    2,151 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.2 & pgsql-13.5
    last update over 1 year ago
    run-tests.sh exception
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 5.6 & MySQL 5.5
    last update over 1 year ago
    2,151 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.2 & pgsql-13.5
    last update over 1 year ago
    2,112 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    run-tests.sh exception
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    2,151 pass
  • Status changed to RTBC over 1 year ago
  • 🇬🇧United Kingdom mcdruid 🇬🇧🇪🇺

    Looks good to me!

    • poker10 committed 1e7ee478 on 7.x
      Issue #2060235 by lauriii, poker10, gaas: Getting a PDOException when...
  • Status changed to Fixed over 1 year ago
  • 🇸🇰Slovakia poker10

    Thanks everyone! Committed.

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

Production build 0.71.5 2024