code: def test_dynamic_fields(self):
      detection = fo.Detection(
          foo="bar",
          embedding=np.random.randn(4),
          custom_id=ObjectId(),
      )
  
      self.assertTrue(detection.has_field("label"))
      self.assertTrue(detection.has_field("foo"))
      self.assertFalse(detection.has_field("spam"))
  
      self.assertIsNone(detection.get_field("label"))
      self.assertEqual(detection.get_field("foo"), "bar")
  
      detection.set_field("label", "cat")
      detection.set_field("foo", "baz")
      detection.set_field("spam", "eggs")
  
      self.assertEqual(detection.get_field("label"), "cat")
      self.assertEqual(detection.get_field("foo"), "baz")
      self.assertEqual(detection.get_field("spam"), "eggs")
  
      # pylint: disable=no-member
      self.assertEqual(detection.label, "cat")
      self.assertEqual(detection.foo, "baz")
      self.assertEqual(detection.spam, "eggs")
  
      d = detection.to_dict()
  
      self.assertIsInstance(d["_id"], ObjectId)
      self.assertIsInstance(d["foo"], str)
      self.assertIsInstance(d["embedding"], Binary)
      self.assertIsInstance(d["_custom_id"], ObjectId)
  
      detection2 = fo.Detection.from_dict(d)
  
      self.assertEqual(detection2.id, detection.id)
      self.assertEqual(detection2["foo"], detection["foo"])
      self.assertIsInstance(detection2["embedding"], np.ndarray)
      self.assertEqual(detection2["custom_id"], detection["custom_id"])
  
      d = detection.to_dict(extended=True)
  
      self.assertIsInstance(d["_id"], dict)
      self.assertIsInstance(d["foo"], str)
      self.assertIsInstance(d["embedding"], dict)
      self.assertIsInstance(d["_custom_id"], dict)
  
      detection2 = fo.Detection.from_dict(d, extended=True)
  
      self.assertEqual(detection2.id, detection.id)
      self.assertEqual(detection2["foo"], detection["foo"])
      self.assertIsInstance(detection2.embedding, np.ndarray)
      self.assertEqual(detection2["custom_id"], detection["custom_id"])
  
file_path: fiftyone/tests/unittests/label_tests.py
imports: import unittest
  from bson import Binary, ObjectId
  import numpy
  import fiftyone
  from decorators import drop_datasets
label_desc: Use image node_id 2 for calling the LabelTests obj's underlying member method code with example usage: obj.test_dynamic_fields() without return types