Problem/Motivation

Some entity may declare a canonical link template, but does not actually provide a route for it. Because of that a Route does not exist exception is thrown in:

    redirect_delete_by_path('internal:/' . $entity->toUrl('canonical')->getInternalPath());

This is not a direct bug of the Redirect module, but some workaround is needed here to prevent it.

Original report

We tried to upgrade Redirect from 8.x-1.0-beta1 to 8.x-1.0 yesterday. The update itself was successful and we had no related module updates or config to import or export etc.

We manage our config using Drush CMI Tools, and as part of that we ignore all Metatag config (so our client can modify them without us overriding them). However, our CI server automatically runs `drush cim`, which started failing yesterday following the update to Redirect.

This is reproduceable locally - we update Redirect, and can no longer run `drush cim` due to the following errors:

root@5595ff00dda9:/var/www/html/docroot# drush cim 
 Collection  Config                                                    Operation 
             metatag.metatag_defaults.user                             delete    
             metatag.metatag_defaults.taxonomy_term                    delete    
             metatag.metatag_defaults.node                             delete    
             metatag.metatag_defaults.global                           delete    
             metatag.metatag_defaults.front                            delete    
             metatag.metatag_defaults.404                              delete    
             metatag.metatag_defaults.403                              delete    
             google_analytics.settings                                 delete    
             contact.form.personal                                     delete    
             commerce_payment.commerce_payment_gateway.braintree       delete
Import the listed configuration changes? (y/n): y 
Synchronized configuration: delete metatag.metatag_defaults.user.                                                                                                                                               [ok]
Synchronized configuration: delete metatag.metatag_defaults.taxonomy_term.                                                                                                                                      [ok]
Synchronized configuration: delete metatag.metatag_defaults.node.                                                                                                                                               [ok]
Synchronized configuration: delete metatag.metatag_defaults.global.                                                                                                                                             [ok]
Synchronized configuration: delete metatag.metatag_defaults.front.                                                                                                                                              [ok]
Synchronized configuration: delete metatag.metatag_defaults.404.                                                                                                                                                [ok]
Synchronized configuration: delete metatag.metatag_defaults.403.                                                                                                                                                [ok]
Synchronized configuration: delete google_analytics.settings.                                                                                                                                                   [ok]
Synchronized configuration: delete contact.form.personal.                                                                                                                                                       [ok]
Synchronized configuration: delete commerce_payment.commerce_payment_gateway.braintree.                                                                                                                         [ok]
Finalizing configuration synchronization.                                                                                                                                                                       [ok]
Drupal\Core\Config\ConfigException: Errors occurred during import in _drush_config_import() (line 703 of /var/www/html/vendor/drush/drush/commands/core/config.drush.inc).                                   [error]
The import failed due for the following reasons:                                                                                                                                                             [error]
Unexpected error during import with operation delete for metatag.metatag_defaults.user: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.taxonomy_term: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.node: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.global: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.front: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.404: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.403: Route "entity.metatag_defaults.canonical" does not exist.

(Snipped other config for brevity.)

I can't figure out what's going on. Has this happened for anyone else? We'd like to upgrade to the stable module version but we can't currently.

Comments

Sophie.SK created an issue. See original summary.

berdir’s picture

I see, this might be caused by #2888903: Delete redirects even the entity lacks the path field but the actual bug here is in metatags.

The issue added an hasLinkTemplate() check for an entity. Apparently the metatag_defaults module *claims* to have a link template but does not actually have one.

I would suggest you report that there. In the meantime, we can add a try/catch around our code or more explicitly check that a route exists before trying to access it, but sure how.

sophie.sk’s picture

Oh interesting! Thanks for getting back to me so quickly.

I'll raise this issue with them, then. I had searched through their issue queue, but couldn't find anything relevant.

sophie.sk’s picture

Created issue #2932285: After updating Redirect to 1.0, config import fails: route does not exist on the Metatag issue queue. Thanks again Berdir, will make sure I keep this one updated.

berdir’s picture

No, the problem is about an entity type defining a link template in the annotation but not having a route for it. Paragraphs doesn't do that.

damienmckenna’s picture

Status: Active » Postponed

Ok, fair point.

I just noticed that the paths defined in the annotation weren't updated when the menu paths were changed ages ago, so I've uploaded a possible fix. Lets see if we can fix it over there.

damienmckenna’s picture

Status: Postponed » Closed (duplicate)

Yeah, we were able to fix this in Metatag; I'll release 8.x-1.4 today. Thanks for your help, Berdir.

berdir’s picture

Status: Closed (duplicate) » Active

Great.

I'll keep this open for now. As I said, I'm open to adding a try/catch around that in case there are other entity types out there that incorrectly define a canonical link template. Metatags was not the first and it will definitely not be the last :)

damienmckenna’s picture

FYI I released Metatag 1.4 which fixes this bug.

akprasad303’s picture

I am also getting similar problem but not exactly Meta tag
Error is :
The import failed due for the following reasons: [error]
Unexpected error during import with operation update for block.block.seven_page_title: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'revision.revision_user' in 'field
list': SELECT revision.revision_id AS revision_id, revision.langcode AS langcode, revision.revision_user AS revision_user, revision.revision_created AS revision_created,
revision.revision_log AS revision_log, base.id AS id, base.type AS type, base.uuid AS uuid, CASE base.revision_id WHEN revision.revision_id THEN 1 ELSE 0 END AS isDefaultRevision
FROM
{block_content} base
INNER JOIN {block_content_revision} revision ON revision.revision_id = base.revision_id; Array
(
)

pingwin4eg’s picture

Similar situation on the project I'm currently working on.

Just installed the Redirect 1.0.0 (not updated). This includes:

  • required dependency in composer.json and composer.lock
  • enabled module in core.extension.yml
  • didn't include config files of Redirect module to the staged config directory

blt setup displays the following error at the end of all output:

Finalizing configuration synchronization.                                                                                                                           [ok]
The import failed due for the following reasons:                                                                                                                    [error]
Unexpected error during import with operation delete for entity_browser.browser.image_browser: Route "entity.entity_browser.canonical" does not exist.
Unexpected error during import with operation delete for entity_browser.browser.media_browser: Route "entity.entity_browser.canonical" does not exist.
Unexpected error during import with operation delete for simple_oauth.oauth2_token.bundle.refresh_token: Route "entity.oauth2_token_type.canonical" does
not exist.
Unexpected error during import with operation delete for simple_oauth.oauth2_token.bundle.auth_code: Route "entity.oauth2_token_type.canonical" does not
exist.
Unexpected error during import with operation delete for simple_oauth.oauth2_token.bundle.access_token: Route "entity.oauth2_token_type.canonical" does
not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.user: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.taxonomy_term: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.node: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.global: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.front: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.404: Route "entity.metatag_defaults.canonical" does not exist.
Unexpected error during import with operation delete for metatag.metatag_defaults.403: Route "entity.metatag_defaults.canonical" does not exist.
Command dispatch complete                                                                                                                                              [notice]
Command dispatch complete                                                                                                                                              [notice]
[Acquia\Blt\Robo\Tasks\DrushTask]  Exit code 1  Time 03:14
[error]   
[error]  Command `internal:drupal:install ` exited with code 1. 
[error]  Command `setup:drupal:install ` exited with code 1. 
berdir’s picture

Yes, as I mentioned, I'm happy to accept a patch that adds a try/catch around the delete and ignores errors.

But ultimately, those erors are bugs in those modules, for example the one about metatags was fixed in the most recent version of the metatags module. Other modules might break in similar ways as this.

pingwin4eg’s picture

Title: After update to 1.0, config import fails: route does not exist » Catch 'Route does not exist' exception when getting entity internal path
Assigned: Unassigned » pingwin4eg
Category: Bug report » Feature request
Issue summary: View changes

Updated issue summary. Going to create a patch with a proposed workaround.

pingwin4eg’s picture

Assigned: pingwin4eg » Unassigned
Status: Active » Needs review
StatusFileSize
new1.46 KB
berdir’s picture

Status: Needs review » Needs work

Thanks. Please put both calls in there, because the second variant might internally also resolve to the route at some point, so lets be sure to catch any exceptions.

Also, there is also #2935026: Deleting entity with external canonical link throws exception, might be easier to include that fix here because it also needs to be inside the try/catch (and we should then re-use the $url object), I can then give credits as well to that user here. Otherwise we'll have to re-roll it after this is in.

jazzslider’s picture

@pingwin4eg, @Berdir:

Did an issue ever get filed in the oauth2 module's queue to fix this similarly to how it was addressed in metatag? I'm advising a client on how to proceed given they're encountering this from oauth2.

Thanks!

damienmckenna’s picture

We fixed the problem in Metatag in 8.x-1.4.

dagmar’s picture

Did an issue ever get filed in the oauth2 module's queue to fix this similarly to how it was addressed in metatag? I'm advising a client on how to proceed given they're encountering this from oauth2.

I just did #2955804: "entity.oauth2_token_type.canonical" does not exist.

davemybes’s picture

I'm seeing the same issue, but only with the entity_browser part:

Unexpected error during import with operation delete for entity_browser.browser.image_browser: Route "entity.entity_browser.canonical" does not exist.
Unexpected error during import with operation delete for entity_browser.browser.media_browser: Route "entity.entity_browser.canonical" does not exist.

The patch for entity.oauth2 works great, but the current patch here doesn't fix the entity_browser issue, I'm afraid. Entity_browser has a ticket in related to this too: https://www.drupal.org/project/entity_browser/issues/2953429. I'd love to help with this, so, @Berdir, if you can point me to where the second call is, I can try my hand at adding it.

berdir’s picture

Status: Needs work » Closed (duplicate)

The second call is directly below :)

#2935026: Deleting entity with external canonical link throws exception did it correctly, closing this as a duplicate.

landsman’s picture

I have same problem as @incrn8. Fresh install of Thunder, importing configuration died on this.

rob230’s picture

#15 solved it for me with entity_browser (unable to delete some views or uninstall the file_browser module). #2935026: Deleting entity with external canonical link throws exception which is apparently committed must have not solved every case.