entities – Am getting EntityMalformedException when saving nodes after applying a patch

I applied the following patch to be able to get JSON response containing all the default metatag information:

Link can be found here

Everything was working fine until I tried to save a new node.
When trying to save any new node, I get the following error:

DrupalCoreEntityEntityMalformedException: The "node" entity cannot have a URI as it does not have an ID in DrupalCoreEntityEntityBase->toUrl() (line 192 of core/lib/Drupal/Core/Entity/EntityBase.php).

May you please help to resolve this patch in a way that no error is thrown when saving nodes?

It’s the only patch I could find that works with our APIs response.