Summary

After updating drupal/simple_oauth, /admin/reports/status shows:
Entity/field definitions: Mismatched entity and/or field definitions OAuth2 token
The Scopes field needs to be updated.

Steps to reproduce

Steps to reproduce
Have a site with simple_oauth already installed (any version prior to the one where setDisplayOptions() was added to the scopes field).
Update simple_oauth to a version where Oauth2Token::baseFieldDefinitions() sets ->setDisplayOptions('view', ...) and ->setDisplayOptions('form', ...) on the scopes field (see src/Entity/Oauth2Token.php).
Run drush updatedb / visit /update.php. No pending hook_update_N or post_update function addresses this.
Visit /admin/reports/status. The "Entity/field definitions" section reports the mismatch and never clears.

Root cause
simple_oauth.install and simple_oauth.post_update.php contain no update hook that calls EntityDefinitionUpdateManager::updateFieldStorageDefinition() for the scopes field's new display options. Comparing the installed field storage definition against the current code-level definition confirms the only difference is the display key (view/form options) — the actual SQL schema (columns, indexes) is unchanged, so this isn't a data-affecting change, just a metadata sync that Drupal's entity system doesn't auto-detect (similar in nature to the core limitation noted in https://www.drupal.org/project/drupal/issues/3005447 and previously hit by this same module in https://www.drupal.org/project/simple_oauth/issues/3320581 for the Token field's index).

Proposed resolution

Add an update hook along these lines:

/**
 * Refreshes the oauth2_token scopes field storage definition.
 */
function simple_oauth_update_XXXX(): void {
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $storage_definition = \Drupal::service('entity_field.manager')
    ->getFieldStorageDefinitions('oauth2_token')['scopes'] ?? NULL;

  if ($storage_definition) {
    $definition_update_manager->updateFieldStorageDefinition($storage_definition);
  }
}

Note: fetching the definition via $definition_update_manager->getFieldStorageDefinition() (as done for a similar, unrelated purpose elsewhere) returns the already-installed (stale) definition rather than the current code-level one, so it does not clear this mismatch — the fix needs to source the definition from entity_field.manager instead.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mohamadrashid created an issue. See original summary.

andres alvarez made their first commit to this issue’s fork.

andres alvarez’s picture

Confirmed the root cause. simple_oauth_update_8605() uninstalls and reinstalls the scopes base field on oauth2_token, but the reinstalled definition omits the view/form setDisplayOptions() calls present in Oauth2Token::baseFieldDefinitions(). Any site that ran that update ends up with an installed field storage definition out of sync with the code-level definition.

Added update_8609() to call updateFieldStorageDefinition() and resync the scopes field, plus a kernel test that reproduces the stale definition and confirms the update fixes it. Test fails without the fix and passes with it. MR opened.

andres alvarez’s picture

Version: 6.1.0 » 6.1.x-dev
Status: Active » Needs review
vidit.anjaria’s picture

vidit.anjaria’s picture

Issue tags: +2026Sprint21
bojan_dev’s picture

Status: Needs review » Postponed (maintainer needs more info)

Thanks for the report and the MR. I don't think display options can cause this warning: Drupal only reports "needs to be updated" when the field's database schema differs, and the MR's test doesn't check that the warning goes away.

The likely cause is the 5.x upgrade problem in #3632599: Update 8605 renames the token scopes column before uninstalling the legacy field: Drupal records the new scopes field, but the table and stored schema are still from 5.x. That gives exactly this warning.

Could you run these on a site that currently shows the warning, before applying the MR or running any further updates:

drush php:eval 'echo \Drupal::service("update.update_hook_registry")->getInstalledVersion("simple_oauth");'
drush sql:query "SHOW CREATE TABLE oauth2_token__scopes"