You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR fixes an issue where FOG Client automatic host registration fails silently when creating a new pending host (Closes#779).
The failure happens because the database schema defines hosts.hostImage as NOT NULL, but the auto-registration code attempts to insert NULL when no image is assigned. As a result, the INSERT ... ON DUPLICATE KEY UPDATE statement is rejected by MySQL, causing Host::save() to return without throwing an exception.
Root Cause
During auto-registration, hosts are created in a pending state.
No image is assigned at this stage.
ORM generates:
hostImage =NULL
Database rejects the insert:
INSERT INTO `hosts` (`hostName`,`hostDesc`,`hostIP`,`hostImage`,`hostBuilding`,`hostCreateDate`,`hostLastDeploy`,`hostCreateBy`,`hostUseAD`,`hostADDomain`,`hostADOU`,`hostADUser`,`hostADPass`,`hostADPassLegacy`,`hostProductKey`,`hostPrinterLevel`,`hostKernelArgs`,`hostKernel`,`hostDevice`,`hostInit`,`hostPending`,`hostPubKey`,`hostSecToken`,`hostSecTime`,`hostPingCode`,`hostExitBios`,`hostExitEfi`,`hostEnforce`,`hostInfoKey`,`hostInfoLock`) VALUES ('EXAMPLE-18','Pending Registration created by FOG_CLIENT','',NULL,'','2026-02-12 22:36:53','','fog','','','','','','','','','','','','','1','','','','','','','1','','') ON DUPLICATE KEY UPDATE `hostName`=VALUES(`hostName`),`hostDesc`=VALUES(`hostDesc`),`hostIP`=VALUES(`hostIP`),`hostImage`=VALUES(`hostImage`),`hostBuilding`=VALUES(`hostBuilding`),`hostCreateDate`=VALUES(`hostCreateDate`),`hostLastDeploy`=VALUES(`hostLastDeploy`),`hostCreateBy`=VALUES(`hostCreateBy`),`hostUseAD`=VALUES(`hostUseAD`),`hostADDomain`=VALUES(`hostADDomain`),`hostADOU`=VALUES(`hostADOU`),`hostADUser`=VALUES(`hostADUser`),`hostADPass`=VALUES(`hostADPass`),`hostADPassLegacy`=VALUES(`hostADPassLegacy`),`hostProductKey`=VALUES(`hostProductKey`),`hostPrinterLevel`=VALUES(`hostPrinterLevel`),`hostKernelArgs`=VALUES(`hostKernelArgs`),`hostKernel`=VALUES(`hostKernel`),`hostDevice`=VALUES(`hostDevice`),`hostInit`=VALUES(`hostInit`),`hostPending`=VALUES(`hostPending`),`hostPubKey`=VALUES(`hostPubKey`),`hostSecToken`=VALUES(`hostSecToken`),`hostSecTime`=VALUES(`hostSecTime`),`hostPingCode`=VALUES(`hostPingCode`),`hostExitBios`=VALUES(`hostExitBios`),`hostExitEfi`=VALUES(`hostExitEfi`),`hostEnforce`=VALUES(`hostEnforce`),`hostInfoKey`=VALUES(`hostInfoKey`),`hostInfoLock`=VALUES(`hostInfoLock`);
ERROR 1048 (23000): Column 'hostImage' cannot be null
The failure is silent, and the host is never created, even though MACs may still be registered.
Solution
This PR explicitly sets the host image to 0 (No Image) during automatic host creation:
->set('imageID', 0)
This issue can be difficult to diagnose because it fails without throwing an exception. Adding the explicit imageID = 0 ensures predictable behavior and aligns auto-registration with existing FOG semantics, where 0 represents //no assigned image//, and fully satisfies the database constraint.
Firstly, thank you for contributing! It is greatly appreciated!
We haven't had the time to test and check this thoroughly yet.
My first thought though is that we don't want to set image Id to 0 as we've had historical issues with various ids being set to 0 and we're trying to avoid that as it can cause issues in later workflows if it doesn't get updated. We probably added a null check for creating a host and this entry point of creating a pending host probably slipped through the cracks. I don't know when I'll have time to dig in and really I would be asking @mastacontrola for help on this one. But we see it, we appreciate it, and we'll work it out.
@darksidemilk thank you for your comments and for reviewing this PR. Actually, when creating a new host manually through Web UI without selecting an image, it sets the hosts.hostImage column on DB to 0, so if this is not desired, I think that the DB Schema should be updated to allow NULL values on this column and be updated as such.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where FOG Client automatic host registration fails silently when creating a new pending host (Closes #779).
The failure happens because the database schema defines
hosts.hostImageasNOT NULL, but the auto-registration code attempts to insertNULLwhen no image is assigned. As a result, theINSERT ... ON DUPLICATE KEY UPDATEstatement is rejected by MySQL, causingHost::save()to return without throwing an exception.Root Cause
INSERT INTO `hosts` (`hostName`,`hostDesc`,`hostIP`,`hostImage`,`hostBuilding`,`hostCreateDate`,`hostLastDeploy`,`hostCreateBy`,`hostUseAD`,`hostADDomain`,`hostADOU`,`hostADUser`,`hostADPass`,`hostADPassLegacy`,`hostProductKey`,`hostPrinterLevel`,`hostKernelArgs`,`hostKernel`,`hostDevice`,`hostInit`,`hostPending`,`hostPubKey`,`hostSecToken`,`hostSecTime`,`hostPingCode`,`hostExitBios`,`hostExitEfi`,`hostEnforce`,`hostInfoKey`,`hostInfoLock`) VALUES ('EXAMPLE-18','Pending Registration created by FOG_CLIENT','',NULL,'','2026-02-12 22:36:53','','fog','','','','','','','','','','','','','1','','','','','','','1','','') ON DUPLICATE KEY UPDATE `hostName`=VALUES(`hostName`),`hostDesc`=VALUES(`hostDesc`),`hostIP`=VALUES(`hostIP`),`hostImage`=VALUES(`hostImage`),`hostBuilding`=VALUES(`hostBuilding`),`hostCreateDate`=VALUES(`hostCreateDate`),`hostLastDeploy`=VALUES(`hostLastDeploy`),`hostCreateBy`=VALUES(`hostCreateBy`),`hostUseAD`=VALUES(`hostUseAD`),`hostADDomain`=VALUES(`hostADDomain`),`hostADOU`=VALUES(`hostADOU`),`hostADUser`=VALUES(`hostADUser`),`hostADPass`=VALUES(`hostADPass`),`hostADPassLegacy`=VALUES(`hostADPassLegacy`),`hostProductKey`=VALUES(`hostProductKey`),`hostPrinterLevel`=VALUES(`hostPrinterLevel`),`hostKernelArgs`=VALUES(`hostKernelArgs`),`hostKernel`=VALUES(`hostKernel`),`hostDevice`=VALUES(`hostDevice`),`hostInit`=VALUES(`hostInit`),`hostPending`=VALUES(`hostPending`),`hostPubKey`=VALUES(`hostPubKey`),`hostSecToken`=VALUES(`hostSecToken`),`hostSecTime`=VALUES(`hostSecTime`),`hostPingCode`=VALUES(`hostPingCode`),`hostExitBios`=VALUES(`hostExitBios`),`hostExitEfi`=VALUES(`hostExitEfi`),`hostEnforce`=VALUES(`hostEnforce`),`hostInfoKey`=VALUES(`hostInfoKey`),`hostInfoLock`=VALUES(`hostInfoLock`); ERROR 1048 (23000): Column 'hostImage' cannot be nullSolution
This PR explicitly sets the host image to
0(No Image) during automatic host creation:This issue can be difficult to diagnose because it fails without throwing an exception. Adding the explicit
imageID = 0ensures predictable behavior and aligns auto-registration with existing FOG semantics, where0represents //no assigned image//, and fully satisfies the database constraint.