Skip to content

Comments

Fix - Use getTableForItemType() for custom dropdown search options to resolve correct shared table name#1147

Merged
stonebuzz merged 2 commits intomainfrom
fix/custom-dropdown-wrong-table-name-in-search-options
Feb 20, 2026
Merged

Fix - Use getTableForItemType() for custom dropdown search options to resolve correct shared table name#1147
stonebuzz merged 2 commits intomainfrom
fix/custom-dropdown-wrong-table-name-in-search-options

Conversation

@RomainLvr
Copy link
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !42293
  • Here is a brief description of what this PR does

When a Fields container contained a field of type dropdown-Glpi\CustomDropdown\*,
the search options were built using CommonDBTM::getTable($class), which bypasses
late static binding and calls getExpectedTableNameForClass() directly. This produces
an incorrect table name (e.g. glpi_customdropdowns_customdropdowndropdowns) instead
of the actual shared table glpi_dropdowns_dropdowns.

This caused two symptoms:

  • A fatal SQL error when saving field values (history construction failing)
  • A fatal SQL error on the item list page when the field was added to default search columns
*** Uncaught PHP Exception RuntimeException: "MySQL query error: Table 'glpi-11bf.glpi_customdropdowns_customdropdowndropdowns' doesn't exist (1146) in SQL query "SELECT `glpi_customdropdowns_customdropdowndropdowns`.`completename`, `glpi_customdropdowns_customdropdowndropdowns`.`comment`, '' AS `transname` FROM `glpi_customdropdowns_customdropdowndropdowns` WHERE `glpi_customdropdowns_customdropdowndropdowns`.`id` = '1'"." at DBmysql.php line 416
  Backtrace :
  ./src/DBmysql.php:416                              
  ./src/DBmysqlIterator.php:126                      DBmysql->doQuery()
  ./src/DBmysql.php:1088                             DBmysqlIterator->execute()
  ./src/DbUtils.php:1468                             DBmysql->request()
  ./src/autoload/dbutils-aliases.php:329             DbUtils->getTreeValueCompleteName()
  ./src/Dropdown.php:565                             getTreeValueCompleteName()
  ./plugins/fields/inc/container.class.php:1545      Dropdown::getDropdownName()
  ./plugins/fields/inc/container.class.php:1441      PluginFieldsContainer::constructHistory()
  ./plugins/fields/front/container.form.php:60       PluginFieldsContainer->updateFieldsValues()
  ...Glpi/Controller/LegacyFileLoadController.php:64 require()
  ./vendor/symfony/http-kernel/HttpKernel.php:181    Glpi\Controller\LegacyFileLoadController->__invoke()
  ./vendor/symfony/http-kernel/HttpKernel.php:76     Symfony\Component\HttpKernel\HttpKernel->handleRaw()
  ./vendor/symfony/http-kernel/Kernel.php:208        Symfony\Component\HttpKernel\HttpKernel->handle()
  ./public/index.php:71                              Symfony\Component\HttpKernel\Kernel->handle()

Fix: Replace CommonDBTM::getTable($class) with getTableForItemType($class), which
correctly calls $class::getTable() and goes through CustomObjectTrait::getTable(),
returning the proper shared table name.

Also use completename as the search field for tree dropdowns (CommonTreeDropdown subclasses)
instead of name, which is consistent with GLPI core search options for tree-based dropdowns.

@RomainLvr RomainLvr self-assigned this Feb 20, 2026
@RomainLvr RomainLvr added the bug label Feb 20, 2026
@stonebuzz stonebuzz merged commit 8b34f0f into main Feb 20, 2026
3 checks passed
@stonebuzz stonebuzz deleted the fix/custom-dropdown-wrong-table-name-in-search-options branch February 20, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants