diff --git a/php/libraries/NDB_BVL_Instrument.class.inc b/php/libraries/NDB_BVL_Instrument.class.inc index 760ef2c6e4b..27942636f5b 100644 --- a/php/libraries/NDB_BVL_Instrument.class.inc +++ b/php/libraries/NDB_BVL_Instrument.class.inc @@ -2106,12 +2106,17 @@ abstract class NDB_BVL_Instrument extends NDB_Page ['CID' => $this->getCommentID()] ); - $this->instanceData = json_decode($jsondata, true) ?? []; + $this->instanceData = json_decode($jsondata ?? '', true) ?? []; } else { $defaults = $db->pselectRow( "SELECT * FROM $this->table WHERE CommentID=:CID", ['CID' => $this->getCommentID()] ); + // This is only included because it's the primary key. JSON + // data does not include it. Unset so that the two types are + // consistent. Places that need the commentID should be using + // NDB_BVL_Instrument->getCommentID() + unset($defaults['CommentID']); $this->instanceData = $defaults ?? []; } diff --git a/test/unittests/NDB_BVL_Instrument_Test.php b/test/unittests/NDB_BVL_Instrument_Test.php index a0a7a97b9d0..9027cddeabd 100644 --- a/test/unittests/NDB_BVL_Instrument_Test.php +++ b/test/unittests/NDB_BVL_Instrument_Test.php @@ -1141,7 +1141,6 @@ function testGetInstanceData() 'ID' => '1000', 'SessionID' => '123', 'Test_name' => 'Test_name1', - 'CommentID' => 'commentID1', 'Data_entry' => '', 'Required_elements_completed' => 'N', 'Administration' => '',