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.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 2916816-7.patch | 3.24 KB | phenaproxima |
| #7 | interdiff-2916816-2-7.txt | 2.33 KB | phenaproxima |
| #2 | 2916816-2.patch | 2.4 KB | phenaproxima |
Comments
Comment #2
phenaproximaAnd patch. With tests.
Comment #3
seanbNice find! Can we make the tests actually do a query by UUID to prove it works?
Comment #4
phenaproximaApparently 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.
Comment #5
phenaproximaIn 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.
drush cget, or your utility of choice, to get the UUID of a media type config entity.drush phpto 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()Comment #6
phenaproximaComment #7
phenaproximaI was able to make it work! Nice hacking, me. :) No need for manual testing.
Comment #8
phenaproximaBumping status to critical, since this blocks the update path.
Comment #9
seanbFor 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.
Even though
config.entity.key_store.media_bundlecould 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.
Comment #10
phenaproximaDid 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.
Comment #11
seanbAhh lazy me skipped the source fields... This totally works!
Comment #13
phenaproximaThanks, @seanB! Committed and pushed.