PDOException: SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'p.rid': SELECT p.rid.* FROM {role} r {} WHERE (r.name = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => authenticated user ) in function _password_policy_load_active_policy()

The problem is that select doesn't include table with alias 'p'. p.rid should be replaced with r.rid.

  // If the role is a name, not an ID, replace with the ID.
  for ($i = 0; $i < count($roles); $i++) {
    if (!is_numeric($roles[$i])) {
      $row = db_select('role', 'r', array('target' => 'slave'))
        ->fields('p.rid')
        ->condition('r.name', $roles[$i])
        ->execute()
        ->fetchAssoc();
      if (!empty($row['rid'])) {
        $roles[$i] = $row['rid'];
      }
    }
  }

Comments

fertant created an issue. See original summary.

fertant’s picture

Fix included

fertant’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: password_policy-table-not-exist-3032886-02.patch, failed testing. View results

aohrvetpv’s picture

fertant, thanks for reporting this bug. How can you cause the error to occur? I am trying to determine the impact of this bug. This code has been present since 2010 but no one has reported a problem before.

I'm not sure why your patch is not applying. You could try creating it per the instructions here:
https://www.drupal.org/project/password_policy/git-instructions

aohrvetpv’s picture

fertant, also, if it is possible to report: What PHP version and database system are you using?

aohrvetpv’s picture

Status: Needs work » Needs review
StatusFileSize
new541 bytes

Patch with same changes as in #2

  • AohRveTPV committed 3ab1a32 on 7.x-1.x authored by fertant
    Issue #3032886 by fertant: Unknown table 'p.rid': SELECT p.rid.* FROM {...
aohrvetpv’s picture

Status: Needs review » Fixed

This seems like an obvious bug fix, so went ahead and committed. Thanks.

Would still like answers to my questions in #5 and #6 if possible. I would like to determine the severity/impact of this bug to decide how soon a new release is needed.

fertant’s picture

PHP version on server 7.0.23-1, on local env 7.2.0. Database MySQL 5.7.
Bug reproduced once I validate password in my form validate hook executing your function _password_policy_constraint_validate($password, $account) and as role I am passing it with names, not rid $account->roles = array("authenticated user" => "authenticated user");

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.