diff --git a/src/Query/Query.php b/src/Query/Query.php
index ff436d12..9da873d5 100644
--- a/src/Query/Query.php
+++ b/src/Query/Query.php
@@ -696,7 +696,10 @@ public function __sleep() {
    * Implements the magic __wakeup() method to reload the query's index.
    */
   public function __wakeup() {
-    if (!isset($this->index) && !empty($this->indexId) && \Drupal::hasContainer()) {
+    if (!isset($this->index)
+        && !empty($this->indexId)
+        && \Drupal::hasContainer()
+        && \Drupal::getContainer()->has('entity_type.manager')) {
       $this->index = \Drupal::entityTypeManager()
         ->getStorage('search_api_index')
         ->load($this->indexId);
