Crop entities not saved for uris that differ only by upper/lower case

Created on 4 March 2021, about 4 years ago
Updated 25 July 2023, over 1 year ago

Problem/Motivation

When two images are uploaded whose name differs only by upper/lower case, the second crop entity is not saved.

Steps to reproduce

  • Install with standard profile.
  • Enable media, crop and focal_point modules.
  • Edit the image media type, under 'Crop configuration', choose the image field.
  • Add a media item of type 'image', with a filename, eg sea.png.
  • Repeat step 4 but with a filename that differs only by case, eg Sea.png

The outcome on MySQL is there is only one row in the crop & crop_field_data tables. No second crop entity is saved.

Using PostgreSQL, this error occurs upon save:

Error: Call to a member function isNew() on null in focal_point_entity_update() (line 79 of modules/contrib/focal_point/focal_point.module).

Proposed resolution

The Crop entity has a uri base field defined:

    $fields['uri'] = BaseFieldDefinition::create('uri')
      ->setLabel(t('URI'))
      ->setDescription(t('The URI of the image crop belongs to.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setSetting('max_length', 255);

Adding setSetting('case_sensitive', TRUE) makes this match the corresponding uri property on the file entity. The error doesn't occur and both crops are saved.

Remaining tasks

  • Write patch.
  • Tests.
  • Upgrade hook.

User interface changes

None.

API changes

None.

Data model changes

The uri column definition changes from:

varchar(255) DEFAULT NULL

to

varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL

πŸ› Bug report
Status

Needs work

Version

2.1

Component

Code

Created by

πŸ‡ΈπŸ‡ͺSweden erik.erskine

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.

Production build 0.71.5 2024