After the 'type' field was removed in #2621674: Add APIs for easier access to media type plugins to the entity class, I started to get the following error in the status report:

Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.

Media
Delete the Type field.

The same problem will be faced by anyone updating from beta1 to follow-up versions.

I traced it to the fact that there is still an entry in my database key_value table with the serialized "type" field in the entry for collection = "entity.definitions.installed" and name = "media.field_storage_definitions".

I attempted to delete it from this DB record, and to alter the media_field_data and media_field_revision to remove the obsolete "type", but this only leads to a WSOD in the status report.. Would it be possible to add a hook_update_N() to delete that field properly?

CommentFileSizeAuthor
#15 2652420_15.patch552 bytesslashrsm
#9 2652420_8.patch557 bytesslashrsm
#4 2652420_4.patch790 bytesslashrsm

Comments

jcnventura created an issue. See original summary.

slashrsm’s picture

Category: Bug report » Support request
Status: Active » Fixed

Core automatically handles changes in entity base fields. No need for modules to handle this manually.

drush entity-updates should do the job.

berdir’s picture

Category: Support request » Bug report
Status: Fixed » Active

No, it doesn't. Modules are expected to do this explicitly. It just provides the API.

See https://www.drupal.org/node/2554097

drush entity-updates should work, but you can't expect everyone to be able to use that.

slashrsm’s picture

Version: 8.x-1.0-beta1 » 8.x-1.x-dev
Category: Bug report » Task
Status: Active » Needs review
StatusFileSize
new790 bytes

Meh... slightly older change record confused me. Here we go.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks!

  • slashrsm committed a73fb78 on 8.x-1.x
    Issue #2652420 by slashrsm, Berdir: Mismatched entity and/or field...
bigbaldy’s picture

I ran into a problem with updating from the previous dev version. Error message below. I resolved it by 1) drush dl media_entity (to install the beta version). 2) drush entup (re-installs the type field) . 3) drush media_entity --dev. 4) drush updb.

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /update.php/start?id=63&op=do_nojs&op=do
StatusText: OK
ResponseText: Recoverable fatal error: Argument 1 passed to Drupal\Core\Entity\EntityDefinitionUpdateManager::uninstallFieldStorageDefinition() must implement interface Drupal\Core\Field\FieldStorageDefinitionInterface, null given, called in /var/www/john/d8/k9agility/drupal/modules/media_entity/media_entity.install on line 22 and defined in Drupal\Core\Entity\EntityDefinitionUpdateManager->uninstallFieldStorageDefinition() (line 198 of /var/www/john/d8/k9agility/drupal/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php).

slashrsm’s picture

Status: Fixed » Needs review
StatusFileSize
new557 bytes

If I do:
- Install site
- Download media_entity beta 1
- Install it
- Update it to 8.x-1.x
- Run database updates

This works and removes type field.

I suspect something (entup?) removed type field before the update hook was run. This patch should make it a bit more robust.

bigbaldy’s picture

I tried to duplicate the problem by reinstalling media_entity from the most recent dev version with the type field and with the most recent dev without the type field. I then tried updating to the most recent dev. In all cases I was not able to reproduce the problem I reported. As you suggest I suspect that drush entity-update fixed an unresolved update in my database. drush entity-update was a command that I had overlooked until I read this issue. Thanks for the help. Not sure how to test the patch without being able to replicate the problem.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

You should be able to reproduce by installing the previous version, run drush entity-updates and afterwards run drush updb.

Sorry for missing this, looks like the correct fix for me.

slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Sorry for causing this in the first place.

  • slashrsm committed 48e5616 on 8.x-1.x
    Issue #2652420 by slashrsm, Berdir, bigbaldy: Mismatched entity and/or...
JamesK’s picture

This update function still fails when updating beta1 sites that have existing media entities. Here's the error from drush updb:
Failed: Unable to delete a field (type in media entity) with data that cannot be purged.

Is there any workaround for this?

slashrsm’s picture

Status: Fixed » Needs review
StatusFileSize
new552 bytes

This should work.

JamesK’s picture

Perfect!

JamesK’s picture

Status: Needs review » Reviewed & tested by the community
slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

  • slashrsm committed 3bbb569 on
    Issue #2652420 by slashrsm: Mismatched entity and/or field definitions...

Status: Fixed » Closed (fixed)

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