Skip to content

Conversation

@MyvTsv
Copy link
Contributor

@MyvTsv MyvTsv commented Feb 2, 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 !41780
  • Fixes an error when deleting a duplicate recipient for the same notification.

NotificationTargetTicket::getFromDBByCrit() expects to get one result, 2 found in query "SELECT id FROM glpi_notificationtargets WHERE glpi_notificationtargets.notifications_id = '83' AND glpi_notificationtargets.items_id = '3' AND glpi_notificationtargets.type = '1'". In ./src/CommonDBTM.php(437) #0 ./src/NotificationTarget.php(160): CommonDBTM->getFromDBByCrit() #1 ./src/NotificationTarget.php(551): NotificationTarget->getFromDBForTarget() #2 ./front/notificationtarget.form.php(40): NotificationTarget::updateTargets() #3 ./src/Glpi/Controller/LegacyFileLoadController.php(64): require('/mnt/diskhome/h...') #4 ./vendor/symfony/http-kernel/HttpKernel.php(181): Glpi\Controller\LegacyFileLoadController->__invoke() #5 ./vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw() #6 ./vendor/symfony/http-kernel/Kernel.php(197): Symfony\Component\HttpKernel\HttpKernel->handle() #7 ./public/index.php(70): Symfony\Component\HttpKernel\Kernel->handle() #8 {main}

Screenshots (if appropriate):

image

@MyvTsv MyvTsv self-assigned this Feb 2, 2026
@MyvTsv MyvTsv requested review from Rom1-B and stonebuzz February 2, 2026 09:33
Copy link
Contributor

@Rom1-B Rom1-B left a comment

Choose a reason for hiding this comment

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

Maybe we should add an SQL unique key?
In that case, we would need to clean up any potential duplicates during migration, just before adding this key.

@stonebuzz
Copy link
Contributor

I agree with Rom1; the issue can be resolved simply by adding a uniqueness key.

The root cause of the problem lies in an internal SQL script used to add notifications/targets to instances. This script does not raise an error when attempting to add a target that already exists in GLPI, which results in duplicate entries in the database.

@MyvTsv MyvTsv requested review from Rom1-B and cedric-anne February 4, 2026 09:38
Comment on lines 4609 to 4613
], [
'id' => '187',
'items_id' => '1',
'type' => '1',
'notifications_id' => '71',
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't seem that the error comes from the GLPI basic data, but from a hack on the instance, so I doubt we need to delete anything here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the target because it was inserted twice (L4380 and L4610). I have to remove it, otherwise I get an error when installing a database.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. However, that leaves a gap in the IDs.

Please correct the errors reported by the CIs and it should be OK.

@MyvTsv MyvTsv requested a review from Rom1-B February 6, 2026 14:13
Comment on lines 4609 to 4613
], [
'id' => '187',
'items_id' => '1',
'type' => '1',
'notifications_id' => '71',
Copy link
Contributor

Choose a reason for hiding this comment

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

OK. However, that leaves a gap in the IDs.

Please correct the errors reported by the CIs and it should be OK.

PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`notifications_id`,`items_id`,`type`),
KEY `items` (`type`,`items_id`),
KEY `notifications_id` (`notifications_id`),
Copy link
Contributor

@Rom1-B Rom1-B Feb 11, 2026

Choose a reason for hiding this comment

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

According to getUselessKeys(), called by the --detect-useless-keys option, the index on notifications_id should be removed. This is what's causing the CI to fail. However, this index is relevant because some queries filter only by notifications_id, without using other columns. These queries will lose performance, but the impact is only measurable from 10,000 rows onward, which is likely rare. So, we can remove it, unless we prefer to modify getUselessKeys() to satisfy the CI.

Suggested change
KEY `notifications_id` (`notifications_id`),

What do you think? @cedric-anne @AdrienClairembault @trasher

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, KEY must be removed since it"s included in unicity.

Copy link
Contributor

Choose a reason for hiding this comment

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

It must be removed in the migration script as well

Copy link
Contributor

Choose a reason for hiding this comment

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

https://dev.mysql.com/doc/refman/8.4/en/multiple-column-indexes.html

If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to look up rows. For example, if you have a three-column index on (col1, col2, col3), you have indexed search capabilities on (col1), (col1, col2), and (col1, col2, col3).

Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com>
Copy link
Contributor

@AdrienClairembault AdrienClairembault left a comment

Choose a reason for hiding this comment

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

Tests are failing.

@trasher
Copy link
Contributor

trasher commented Feb 11, 2026

Tests are failing.

Yes, because of #22942 (comment)

@MyvTsv MyvTsv requested review from Rom1-B and stonebuzz and removed request for stonebuzz February 11, 2026 16:38
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.

6 participants