Skip to content

Conversation

@stonebuzz
Copy link
Contributor

@stonebuzz stonebuzz commented Sep 2, 2025

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

Fixing an SQL Error When Adding a Computer Statically to a Computer Group

SQL: INSERT INTO `glpi_plugin_databaseinventory_computergroupstatics` 
(`computers_id`, `plugin_databaseinventory_computergroups_id`) 
VALUES ('2', '')
Error: Incorrect integer value: '' for column 'plugin_databaseinventory_computergroups_id' at row 1
Backtrace:
src/DBmysql.php:1376          DBmysql->doQuery()
src/CommonDBTM.php:726        DBmysql->insert()
src/CommonDBTM.php:1345       CommonDBTM->addToDB()
...tabaseinventory/front/computergroup.form.php:72  CommonDBTM->add()
public/index.php:82           require()

Cause:
The error occurs because the plugin_databaseinventory_computergroups_id value is empty.

This happens because the item variable passed to Twig is loaded from PluginDatabaseinventoryDatabaseParam instead of PluginDatabaseinventoryComputerGroup. As a result, the code tries to insert an empty string into an integer column, which SQL rejects.

Fix : #71

Screenshots (if appropriate):

@stonebuzz stonebuzz requested a review from Lainow September 2, 2025 09:49
@stonebuzz stonebuzz self-assigned this Sep 2, 2025
@stonebuzz stonebuzz added the bug Something isn't working label Sep 2, 2025
@stonebuzz stonebuzz force-pushed the fix_static_sql_error branch from 25d5645 to 9eefadd Compare September 4, 2025 13:18
@stonebuzz stonebuzz merged commit 8080f97 into main Sep 4, 2025
3 checks passed
@stonebuzz stonebuzz deleted the fix_static_sql_error branch September 4, 2025 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1.0.3 : impossible to add a computer in static group

2 participants