diff --git a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/DedupeEntity.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/DedupeEntity.php
index a690ce5..58bcdf8 100644
--- a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/DedupeEntity.php
+++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/DedupeEntity.php
@@ -7,6 +7,11 @@
 
 namespace Drupal\migrate\Plugin\migrate\process;
 
+use Drupal\Core\Entity\Query\QueryFactory;
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Drupal\migrate\Entity\MigrationInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
 /**
  * Ensures value is not duplicated against an entity field.
  *
@@ -14,30 +19,45 @@
  *   id = "dedupe_entity"
  * )
  */
-class DedupeEntity extends DedupeBase {
+class DedupeEntity extends DedupeBase implements ContainerFactoryPluginInterface {
 
   /**
-   * @var \Drupal\Core\Entity\Query\QueryInterface
+   * @var \Drupal\Core\Entity\Query\QueryFactoryInterface
    */
-  protected $entityQuery;
+  protected $entityQueryFactory;
 
   /**
    * {@inheritdoc}
    */
-  protected function exists($value) {
-    return $this->getEntityQuery()->condition($this->configuration['field'], $value)->count()->execute();
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, QueryFactory $entity_query_factory) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition);
+    $this->entityQueryFactory = $entity_query_factory;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
+    return new static(
+      $configuration,
+      $plugin_id,
+      $plugin_definition,
+      $migration,
+      $container->get('entity.query')
+    );
   }
 
   /**
-   * Returns an entity query object.
-   *
-   * @return \Drupal\Core\Entity\Query\QueryInterface
-   *   The entity query object for the configured entity type.
+   * {@inheritdoc}
    */
-  protected function getEntityQuery() {
-    if (!isset($this->entityQuery)) {
-      $this->entityQuery = \Drupal::entityQuery($this->configuration['entity_type']);
-    }
-    return $this->entityQuery;
+  protected function exists($value) {
+    // Plugins are cached so for every run we need a new query object.
+    return $this
+      ->entityQueryFactory
+      ->get($this->configuration['entity_type'], 'AND')
+      ->condition($this->configuration['field'], $value)
+      ->count()
+      ->execute();
   }
+
 }
diff --git a/core/modules/migrate/tests/Drupal/migrate/Tests/process/DedupeEntityTest.php b/core/modules/migrate/tests/Drupal/migrate/Tests/process/DedupeEntityTest.php
index 1060acd..c7a2db5 100644
--- a/core/modules/migrate/tests/Drupal/migrate/Tests/process/DedupeEntityTest.php
+++ b/core/modules/migrate/tests/Drupal/migrate/Tests/process/DedupeEntityTest.php
@@ -6,7 +6,6 @@
 
 namespace Drupal\migrate\Tests\process;
 
-use Drupal\Core\Entity\Query\QueryInterface;
 use Drupal\migrate\Plugin\migrate\process\DedupeEntity;
 
 /**
@@ -23,10 +22,27 @@ class DedupeEntityTest extends MigrateProcessTestCase {
    * The mock entity query.
    *
    * @var \Drupal\Core\Entity\Query\QueryInterface
+   * @var \Drupal\Core\Entity\Query\QueryFactory
    */
   protected $entityQuery;
 
   /**
+   * The mock entity query factory.
+   *
+   * @var  \Drupal\Core\Entity\Query\QueryFactory|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entityQueryFactory;
+
+  /**
+   * The migration configuration, initialized to set the ID to test.
+   *
+   * @var array
+   */
+  protected $migrationConfiguration = array(
+    'id' => 'test',
+  );
+
+  /**
    * {@inheritdoc}
    */
   public static function getInfo() {
@@ -44,6 +60,12 @@ protected function setUp() {
     $this->entityQuery = $this->getMockBuilder('Drupal\Core\Entity\Query\QueryInterface')
       ->disableOriginalConstructor()
       ->getMock();
+    $this->entityQueryFactory = $this->getMockBuilder('Drupal\Core\Entity\Query\QueryFactory')
+      ->disableOriginalConstructor()
+      ->getMock();
+    $this->entityQueryFactory->expects($this->any())
+      ->method('get')
+      ->will($this->returnValue($this->entityQuery));
     parent::setUp();
   }
 
@@ -60,10 +82,9 @@ public function testDedupe($count, $postfix = '') {
     if ($postfix) {
       $configuration['postfix'] = $postfix;
     }
-    $plugin = new TestDedupeEntity($configuration, 'dedupe_entity', array());
+    $plugin = new DedupeEntity($configuration, 'dedupe_entity', array(), $this->getMigration(), $this->entityQueryFactory);
     $this->entityQueryExpects($count);
-    $plugin->setEntityQuery($this->entityQuery);
-    $return = $plugin->transform('test', $this->migrateExecutable, $this->row, 'testpropertty');
+    $return = $plugin->transform('test', $this->migrateExecutable, $this->row, 'testproperty');
     $this->assertSame($return, 'test' . ($count ? $postfix . $count : ''));
   }
 
@@ -105,9 +126,3 @@ protected function entityQueryExpects($count) {
       ->will($this->returnCallback(function () use (&$count) { return $count--;}));
   }
 }
-
-class TestDedupeEntity extends DedupeEntity {
-  public function setEntityQuery(QueryInterface $entity_query) {
-    $this->entityQuery = $entity_query;
-  }
-}
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Block.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Block.php
index 8c527df..2099ae0 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Block.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Block.php
@@ -109,6 +109,7 @@ public function prepareRow(Row $row) {
   public function getIds() {
     $ids['module']['type'] = 'string';
     $ids['delta']['type'] = 'string';
+    $ids['theme']['type'] = 'string';
     return $ids;
   }
 
