Skip to content

Conversation

@MyvTsv
Copy link
Contributor

@MyvTsv MyvTsv commented Jan 15, 2026

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

  • It fixes !41481
  • An SQL error occurs when transferring a computer from one entity to another when it has software with an identical version present in both the source entity and the target entity.
[2026-01-15 16:30:44] glpi.ERROR:   *** Caught RuntimeException: MySQL query error: Duplicate entry 'Computer-14-35' for key 'unicity' (1062) in SQL query "UPDATE `glpi_items_softwareversions` SET `softwareversions_id` = '35' WHERE `id` = '22'".
  Backtrace :
  ./src/DBmysql.php:404                              
  ./src/DBmysql.php:1481                             DBmysql->doQuery()
  ./src/Transfer.php:1718                            DBmysql->update()
  ./src/Transfer.php:1275                            Transfer->transferItemSoftwares()
  ./src/Transfer.php:250                             Transfer->transferItem()
  ./front/transfer.action.php:51                     Transfer->moveItems()
  ...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:197        Symfony\Component\HttpKernel\HttpKernel->handle()
  ./public/index.php:71                              Symfony\Component\HttpKernel\Kernel->handle()

Steps to reproduce

In the source entity

  1. Create a software.
  2. Assign two versions with the same name to this software.
  3. Create a computer.
  4. Assign the two versions of the same software to the computer.

In the target entity

  1. Create a software.
  2. Assign one version with the same name as the versions created in the source entity.

When transferring the computer to the target entity, an SQL error occurs.

@MyvTsv MyvTsv self-assigned this Jan 15, 2026
@MyvTsv MyvTsv requested review from Rom1-B and stonebuzz January 15, 2026 15:44
@trasher
Copy link
Contributor

trasher commented Jan 16, 2026

Seems like #22624 tries to address the same issue.

'glpi_items_softwareversions',
[
'softwareversions_id' => $newversID,
$soft_version_existing = $DB->request([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably using a prepared statement would improve performances.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, probably using prepared statements for delete and update queries would also improve performances on large software sets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants