diff --git a/privatemsg.module b/privatemsg.module index 5f9c69c..98ee648 100755 --- a/privatemsg.module +++ b/privatemsg.module @@ -511,7 +511,11 @@ function privatemsg_thread_load($thread_id, $account = NULL, $start = NULL, $use if (!$thread['read_all']) { $conditions['account'] = $account; } - $thread['messages'] = privatemsg_message_load_multiple($query->execute()->fetchCol(), $conditions); + + $pmids = $query->execute()->fetchCol(); + if (!empty($pmids)) { + $thread['messages'] = privatemsg_message_load_multiple($pmids, $conditions); + } // If there are no messages, don't allow access to the thread. if (empty($thread['messages'])) { diff --git a/privatemsg.test b/privatemsg.test index a805478..e0a3cdc 100644 --- a/privatemsg.test +++ b/privatemsg.test @@ -85,6 +85,10 @@ class PrivatemsgTestCase extends PrivatemsgBaseTestCase { $subject = $this->randomName(20); $body = $this->randomName(50); + // Because of a quirk in the entity_load function, $no_recipient should be involved in another, unrelated thread. + // see https://drupal.org/node/2033161 + $unrelated = privatemsg_new_thread(array($no_recipient), $subject, $body, array('author' => $author)); + $response = privatemsg_new_thread(array($recipient), $subject, $body, array('author' => $author)); $this->drupalLogin($user_no_read_msg);