diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
index 8a26ec0..234ad2a 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
@@ -311,6 +311,14 @@ public function save(EntityInterface $entity) {
       $entity->original = $this->load($id);
     }
 
+    // Build an ID if none is set.
+    if (!isset($entity->{$this->idKey})) {
+      $entity->{$this->idKey} = $entity->id();
+    }
+
+    $entity->preSave($this);
+    $this->invokeHook('presave', $entity);
+
     if ($id !== $entity->id()) {
       // Renaming a config object needs to cater for:
       // - Storage controller needs to access the original object.
@@ -319,14 +327,6 @@ public function save(EntityInterface $entity) {
       $config = $this->configFactory->rename($prefix . $id, $prefix . $entity->id());
     }
 
-    // Build an ID if none is set.
-    if (!isset($entity->{$this->idKey})) {
-      $entity->{$this->idKey} = $entity->id();
-    }
-
-    $entity->preSave($this);
-    $this->invokeHook('presave', $entity);
-
     // Retrieve the desired properties and set them in config.
     foreach ($entity->getExportProperties() as $key => $value) {
       $config->set($key, $value);
