Add directory fails after enabling by-user checks

Created on 30 April 2023, about 1 year ago
Updated 1 June 2023, about 1 year ago

Problem/Motivation

When by-user checks is enabled, clicking on Add Directory results in the following error:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "anonymous" LINE 4: WHERE "uid" <> 'anonymous' ^: SELECT "t"."uid" AS "uid", "t"."name" AS "name" FROM "users_field_data" "t" WHERE "uid" <> :db_condition_placeholder_0 ORDER BY "t"."name" ASC NULLS FIRST; Array ( [:db_condition_placeholder_0] => anonymous ) in Drupal\pfdp\Form\DirectoryForm->getUsers() (line 153 of modules/contrib/private_files_download_permission/src/Form/DirectoryForm.php).

Drupal\Core\Database\StatementWrapper->execute() (Line: 765)
Drupal\Core\Database\Connection->query() (Line: 191)
Drupal\pgsql\Driver\Database\pgsql\Connection->query() (Line: 525)
Drupal\Core\Database\Query\Select->execute() (Line: 155)
Drupal\pgsql\Driver\Database\pgsql\Select->execute() (Line: 153)
Drupal\pfdp\Form\DirectoryForm->getUsers() (Line: 62)
Drupal\pfdp\Form\DirectoryForm->form() (Line: 106)
Drupal\Core\Entity\EntityForm->buildForm()
call_user_func_array() (Line: 534)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 281)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 686)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

Drupal 10.0.8
Postgres 13.7
PHP 8.2.5

Go to Settings and enable by-user checks.
Go to Add Directory, and the error occurs

🐛 Bug report
Status

Fixed

Version

3.1

Component

Code

Created by

🇸🇦Saudi Arabia ishore

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ishore
  • 🇸🇦Saudi Arabia ishore

    Changing this line:

    ->condition('uid', RoleInterface::ANONYMOUS_ID, '<>')

    to:

    ->condition('uid', '0', '<>')

    appears to have fixed the error for me.

  • Assigned to zanonmark
  • Status changed to Postponed: needs info about 1 year ago
  • 🇮🇹Italy zanonmark

    Thanks for reporting Your issue.

    However, I wasn't able to reproduce it. Enabling 'By-user checks' and then clicking on 'Add directory' was flawless, as concretely adding a directory.

    Did You clear the cache after installing / updating the module?

    Thanks,
    MZ

  • 🇸🇦Saudi Arabia ishore

    I'm not sure. So I re-instated the original DirectoryForm.php, cleared the cache, clicked on Add Directory, and the error is still there.

    Could this be a Postgres vs MySQL thing?

  • 🇮🇹Italy zanonmark

    Thanks for reporting this issue, which actually seems like a bug indeed - and a one lying there for about 10 years, since they actually changed that constant from an integer to a string (I guess most of the people here is using MySQL, which probably casts strings to 0?).

    Only, I replaced with an integer, not a string.
    Could You please check the latest code and tell me if everything works for You?

    Thanks,
    MZ

  • Status changed to Needs review about 1 year ago
  • 🇸🇦Saudi Arabia ishore

    Hello

    Where would I find the latest code? I am already at 3.1.0 and I don't see a newer version in the Git repo.

    The change I previously mentioned that I made to DirectoryForm.php has not caused any errors since, and the module is working fine for me. I'm not sure if it would throw up errors for MySQL users though.

  • Status changed to Fixed about 1 year ago
  • 🇮🇹Italy zanonmark

    Thanks for Your info.

    I just released 3.1.1 which checks against 0 (integer) instead of '0' (string) or the previous constant (string too).
    It works well under MySQL too.

    Thanks,
    MZ

  • 🇸🇦Saudi Arabia ishore

    Upgraded to 3.1.1, and it's working fine. Thanks!

  • Status changed to Fixed about 1 year ago
  • 🇮🇹Italy zanonmark

    Thank You,
    MZ

Production build 0.69.0 2024