PDOException: SQLSTATE[42P01]: Undefined table ldapauth - incorrect usage of db_field_exists() on non-existing table

Created on 12 August 2022, over 2 years ago
Updated 4 January 2024, 11 months ago

Problem/Motivation

From Drupal 7.90 and the recent PostgreSQL changes in Drupal 7 core (see: πŸ› pg_attribute.attrelid error Needs review ), there is an error thrown in ldap_authorization submodule.

PDOException: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "ldapauth" does not exist
SELECT 1 FROM pg_attribute WHERE attrelid = :key::regclass AND attname = :column AND NOT attisdropped AND attnum > 0; Array
(
    [:key] => ldapauth
    [:column] => ldapgroups_in_dn
)
 in db_field_exists() (line 2896 of includes/database/database.inc).

The problem started to appear because of changes in DatabaseSchema_pgsql::fieldExists() function, but the root cause is the wrong usage of the db_field_exists() by ldap_authorization module. Problematic function is function ldap_authorization_requirements($phase) and specifically this part:

if ($phase != "install" && db_field_exists('ldapauth', 'ldapgroups_in_dn')) {
  $requirements['ldap_authorization_ldap_integration']['title'] = t('LDAP Integration LDAP Groups Upgrade Concern');
  $requirements['ldap_authorization_ldap_integration']['severity'] = REQUIREMENT_WARNING;
  $requirements['ldap_authorization_ldap_integration']['value'] = NULL;
  $requirements['ldap_authorization_ldap_integration']['description'] = t('Upgrade from Drupal 6 LDAP Groups to Drupal 7
    LDAP Authorization is not automatic.  LDAP Authorization will need to be configured by hand.
    The authorization options are different and automated updgrade is not possible.
    See also. See http://drupal.org/node/1023016, http://drupal.org/node/1183192.
    This message will go away when the ldapauth database table is removed.');
}

According to the last line of the description, I suppose that the check here has to verify if the table ldapauth is present. The correct function to check if a table exists is db_table_exists(), but the module is using the db_field_exists() function. From the recent core changes it is not possible to use db_field_exists() on non-existing tables anymore and the correct code should verify first if the table exists and only then check the existence of the concrete column. Therefore I am creating this as a bug in LDAP, because Drupal core is handling the situation correctly.

This affects only PostgreSQL installations.

Steps to reproduce

Use PostgreSQL database
Install and enable ldap_authorization submodule
Go to status report or other page, where the hook_requirements is invoked
See the error

Proposed resolution

Change the db_field_exists() to db_table_exists()

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: outdated

Version

2.0

Component

Code

Created by

πŸ‡ΈπŸ‡°Slovakia poker10

Live updates comments and jobs are added and updated live.
  • PostgreSQL

    Particularly affects sites running on the PostgreSQL database.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024