Refactor host validation and save logic#785
Refactor host validation and save logic#785mastacontrola merged 1 commit intoFOGProject:dev-branchfrom
Conversation
|
Firstly, thank you for contributing! It is greatly appreciated! |
|
@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 |
|
This appears to be the correct action. While the grand hope is we don't need the imageID when it's not required, this isn't going to hurt anything I can imagine. |
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.