UsageImpact stops on "Duplicate entry" when an asset has no infocom dates

オープン
#395 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
mysql, php
領域
backend, databases

調査の方向性

Start by reading Toolbox::getOldestAssetDate(), findTemporalGapsInTable(), and AbstractAsset::evaluateItem(), which the issue identifies as the path that produces the duplicate entry. Reproduce with an asset that has no use, delivery, or buy date and whose creation date includes a time; then verify that repeated UsageImpact runs complete without a duplicate key error and continue calculating later assets.

索引モデルが issue の本文から書いたものです。

説明

GLPI version: 11.0.11
Plugin version: 1.3.1 (same code in 1.4.0)

Bug description
When an asset has no use, delivery or buy date in its financial information, Toolbox::getOldestAssetDate() returns date_creation with its time part, for example 2026-04-27 15:44:40. Only infocom dates are reset to midnight.
findTemporalGapsInTable() then filters on date >= '2026-04-27 15:44:40', so the row already calculated for 2026-04-27 00:00:00 falls outside the window and the first day is seen as a gap. AbstractAsset::evaluateItem() sets the cursor back to midnight and inserts that day again, which fails on the unicity key.
The exception is not caught per asset: the whole UsageImpact run ends in "Execution error", and every asset after this one is no longer calculated. On our instance the task failed every day for ten days, with 22 assets in this case.

Relevant log output

[2026-11-10 08:58:18] glpi.ERROR: *** Caught RuntimeException: MySQL query error: Duplicate entry 'Computer-16576-2026-04-27 00:00:00' for key 'unicity' (1062) in SQL query "INSERT INTO `glpi_plugin_carbon_carbonemissions` ...

Steps to reproduce

  1. Create a computer with a usage profile and a known power, with no use, delivery or buy date. Its date_creation has a time part.
  2. Run UsageImpact: history is calculated from the creation day.
  3. Run UsageImpact again the next day: duplicate entry on the creation day, the task is in error.

Anything else?
Workaround: set a use date on the asset. A fix could be to reset the date returned by getOldestAssetDate() to midnight in every case, and to catch the error per asset so that one asset does not block the others.

Laurent Tison, Afnic

主要言語
PHP
スター
5
フォーク
7
平均マージ
2時間 26分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pluginsGLPI/carbon のほかの issue

pluginsGLPI/carbon の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。