Problem/Motivation

After running the cross-grade from Media Entity to core Media, it is impossible to query for media type entities by their UUID. This breaks anything which tries to load media types by UUID.

The reason this breaks is because the entity system is maintaining an internal key-value store which maps UUIDs to config entity IDs. This is normally updated when a config entity is saved. But since Media Entity's update path never actually saves the media types at the entity level --
unless the source field is proactively created during the update, that is -- most media types become invisible to entity queries.

Proposed resolution

media_entity_update_8201() needs to re-save every media type, even if it doesn't change them.

Remaining tasks

Patch, review, commit.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Status: Active » Needs review
StatusFileSize
new2.4 KB

And patch. With tests.

seanb’s picture

Status: Needs review » Needs work

Nice find! Can we make the tests actually do a query by UUID to prove it works?

phenaproxima’s picture

Status: Needs work » Needs review

Apparently not. The tests insist the the media_type entity type does not exist, and therefore cannot be queried. Which isn't true at all, of course, but I think the test is under this impression because the web server (which has actually had the update applied) is not the same PHP process/memory space as the test.

So unfortunately, this is probably the best I can do for the moment, although I too would prefer to execute an actual query as proof that it works.

phenaproxima’s picture

In discussion with @seanB, we decided to leave instructions here explaining how to test this, in case we can't figure out a way to do it in the test.

  1. Set up your Drupal with Media Entity 1.x.
  2. Update to 2.x like normal.
  3. Use drush cget, or your utility of choice, to get the UUID of a media type config entity.
  4. Use drush php to get into a Drupal-aware PHP console, and run this code: \Drupal::entityTypeManager()->getStorage('media_type')->getQuery()->condition('uuid', 'known_uuid_of_a_media_type')->execute()
  5. Without this patch, you will get no result from this query. With this patch, you will!
phenaproxima’s picture

Issue tags: +Needs manual testing
phenaproxima’s picture

Issue tags: -Needs manual testing
StatusFileSize
new2.33 KB
new3.24 KB

I was able to make it work! Nice hacking, me. :) No need for manual testing.

phenaproxima’s picture

Priority: Normal » Critical

Bumping status to critical, since this blocks the update path.

seanb’s picture

Status: Needs review » Needs work

For some reason the query by UUID worked without the patch after the upgrade. I see the UUID twice in the key/value store after I exported it.

  • config.entity.key_store.media_bundle
  • config.entity.key_store.media_type

Even though config.entity.key_store.media_bundle could probably be removed, I see no reason why the query should fail? Could you provide more information about the scenario where this fails?

BTW I'm updating from a 8.3.x install with media_entity, media_entity_image and media_entity_document. I have a type for each of the sources.
I updates core to the latest 8.4.x version, updated media_entity to the latest 8.x-2.x version and also added the dev version for media_entity_generic.

phenaproxima’s picture

Did the media types you created have source fields? If not, the media types were re-saved during the update, which would cause them to be placed in the key-value store.

This patch accounts for media types which already have a source field configured; such types are never re-saved, not placed in the proper key-value store, and thus become unqueryable.

seanb’s picture

Status: Needs work » Reviewed & tested by the community

Ahh lazy me skipped the source fields... This totally works!

  • phenaproxima authored 37eea54 on 8.x-2.x
    Issue #2916816 by phenaproxima, seanB: After update, media types cannot...
phenaproxima’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, @seanB! Committed and pushed.

Status: Fixed » Closed (fixed)

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