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

Đang mở
#395 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
mysql, php
Lĩnh vực
backend, databases

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
PHP
Star
5
Fork
7
Merge trung bình
2 giờ 26 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pluginsGLPI/carbon

Tất cả issue của pluginsGLPI/carbon

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.