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.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | redirect-catch-route-does-not-exist-2932263-15.patch | 1.46 KB | pingwin4eg |
Comments
Comment #2
berdirI 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.
Comment #3
sophie.skOh 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.
Comment #4
sophie.skCreated 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.
Comment #5
damienmckennaWouldn't this also trip up Paragraphs? See #2753623: Canonical link template when using not "Default" view mode. Also, see this core issue: #1275902: Allow entity URI callbacks to indicate that the entity has no URI, and make the User module use that for anonymous users
Comment #6
berdirNo, 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.
Comment #7
damienmckennaOk, 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.
Comment #8
damienmckennaYeah, we were able to fix this in Metatag; I'll release 8.x-1.4 today. Thanks for your help, Berdir.
Comment #9
berdirGreat.
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 :)
Comment #10
damienmckennaFYI I released Metatag 1.4 which fixes this bug.
Comment #11
akprasad303 commentedI 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
(
)
Comment #12
pingwin4egSimilar situation on the project I'm currently working on.
Just installed the Redirect 1.0.0 (not updated). This includes:
blt setupdisplays the following error at the end of all output:Comment #13
berdirYes, 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.
Comment #14
pingwin4egUpdated issue summary. Going to create a patch with a proposed workaround.
Comment #15
pingwin4egComment #16
berdirThanks. 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.
Comment #17
jazzslider commented@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!
Comment #18
damienmckennaWe fixed the problem in Metatag in 8.x-1.4.
Comment #19
dagmarI just did #2955804: "entity.oauth2_token_type.canonical" does not exist.
Comment #20
davemybes commentedI'm seeing the same issue, but only with the entity_browser part:
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.
Comment #21
berdirThe second call is directly below :)
#2935026: Deleting entity with external canonical link throws exception did it correctly, closing this as a duplicate.
Comment #22
landsman commentedI have same problem as @incrn8. Fresh install of Thunder, importing configuration died on this.
Comment #23
rob230 commented#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.