From 68419b11305fad2d7628eb8f1bd0e52ba799058a Mon Sep 17 00:00:00 2001 From: Joseph Tingiris Date: Thu, 23 Jan 2020 16:48:14 -0500 Subject: [PATCH] Fix FatalThrowableError in forgetAttrib() (#11064) * From a device's SNMP edit form, when attempting to remove previously set Max Repeaters or Max OIDs values, a fatal error was being thrown. * Fix Call to a member function delete() on null {"userId":2,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function delete() on null at /opt/librenms/app/Models/Device.php:406) * This patch corrects the ability to use the device's SNMP edit form to remove device attributes that had been previously set. The values of Max Repeaters or MaxOIDs can now be deleted from the database. --- app/Models/Device.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Models/Device.php b/app/Models/Device.php index 38ca180499..f197ce620f 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -401,8 +401,11 @@ class Device extends BaseModel }); if ($attrib_index !== false) { + $deleted=(bool)$this->attribs->get($attrib_index)->delete(); + // only forget the attrib_index after delete, otherwise delete() will fail fatally with: + // Symfony\\Component\\Debug\Exception\\FatalThrowableError(code: 0): Call to a member function delete() on null $this->attribs->forget($attrib_index); - return (bool)$this->attribs->get($attrib_index)->delete(); + return $deleted; } return false;