When upgrading from 8.4.2 to 8.4.3, when I tried to create new content, even basic/advanced, I got this error message:

The website encountered an unexpected error. Please try again later.Drupal\Core\Entity\EntityMalformedException: The "node" entity cannot have a URI as it does not have an ID in Drupal\Core\Entity\Entity->toUrl() (line 180 of core/lib/Drupal/Core/Entity/Entity.php).

Reverting to core 8.4.2 fixed the problem.

Comments

jlsegul created an issue. See original summary.

cilefen’s picture

Component: base system » node system
Issue tags: -entity, -create content
timmillwood’s picture

Issue tags: +Needs tests

It'd be awesome to see a test replicating the issue.

Is it possible to replicate on a clean install of 8.4.3? or only after upgrading from 8.4.2?
How about a clean install of 8.4.2, then upgrade to 8.4.3?

jlsegul’s picture

It only appears to happen from an upgrade from 8.4.2 to 8.4.3 on my production site. A new site I'm building with 8.4.3 doesn't have the problem.

jlsegul’s picture

I tried upgrading to 8.4.4 and the same error occurs. I tried creating a new content type and the same error occurs. Anything with the node/add/xxx path throws up this error. It really makes no sense why it would lose the ID on upgrade.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markasourus’s picture

I've run into this problem when updating from 8.3.7 to 8.4.5 also. I haven't found a solution yet.

berdir’s picture

Status: Active » Postponed (maintainer needs more info)

This is usually a custom module/template that calls toUrl() on an unsaved entity, which is not allowed.

Enable verbose error logging which should print a backtrace, post that here.

markasourus’s picture

I updated my site from 8.3.7 to 8.4.2 without an issue. Updated to 8.5.0 when it was released. Got the same error but pointing to a different line number. Enabled verbose logging with backtrace information as described here

Here's what came back.

The website encountered an unexpected error. Please try again later.Drupal\Core\Entity\EntityMalformedException: The "node" entity cannot have a URI as it does not have an ID in Drupal\Core\Entity\Entity->toUrl() (line 189 of core\lib\Drupal\Core\Entity\Entity.php).

Drupal\pathauto\PathautoState->getValue() (Line: 140)
Drupal\Core\Field\FieldItemBase->__get('pathauto') (Line: 116)
Drupal\Core\Field\FieldItemList->__get('pathauto') (Line: 54)
Drupal\pathauto\PathautoWidget->formElement(Object, 0, Array, Array, Object) (Line: 335)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 202)
Drupal\Core\Field\WidgetBase->formMultipleElements(Object, Array, Object) (Line: 104)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 171)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 122)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 115)
Drupal\node\NodeForm->form(Array, Object) (Line: 117)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('node_article_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('node_article_form', Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object) (Line: 113)
Drupal\node\Controller\NodeController->add(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
berdir’s picture

That's coming from pathauto, strange.

Make sure that you are using an up to date version of pathauto, there has not been a toUrl() call in PathautoState in a *very* long time. Not since 29.11.2015 to be exact. You need to keep your contrib modules up to date, not just drupal core, because minor versions tend to introduce changes that can break contrib modules in subtle (and sometimes not so subtle ways..)

markasourus’s picture

I usually update the contributed modules first, take a backup, and then update the core. Pathauto wasn't listed as an available update when I updated to 8.4.2. Browsing the pathauto files, I see a reference that it's for 8.x and that should be the latest version available.

berdir’s picture

Can you post the content of the pathauto.info.yml file?

markasourus’s picture

StatusFileSize
new57.32 KB
new40.36 KB

I downloaded the latest pathauto zip file from Drupal and compared them to what I have and they aren't the same. Not sure why it wasn't listed as an available update. I attached a screenshot comparing the differences of the pathauto.info.yml files and the list of available updates as displayed from my Drupal site.

berdir’s picture

Category: Bug report » Support request
Status: Postponed (maintainer needs more info) » Fixed
Issue tags: -Needs tests

Because the version you had wasn't from drupal.org, you probably installed it years ago from github, Drupal didn't know how to update that as it didn't have the required information in the info.yml file.

Marking this as fixed.

markasourus’s picture

I inherited this site so it's quite possible the original developers might have gotten it from there when it was developed in Drupal 6. I'll replace it with the latest version from Drupal. Thanks for your help.

jlsegul’s picture

Based on this information, I also found out that the pathauto mod was causing my problem. The file structure of the module was different from the current zip file even though the version number was the same. Thanks for the help.

Status: Fixed » Closed (fixed)

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