Repository: voxel51/fiftyone

Issue:
[BUG] RuntimeError when setting session color_scheme
### Describe the problem

Session client fails to post event `set_color_scheme` to web API.

```python
>>> session.color_scheme = fo.ColorScheme()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.11/site-packages/fiftyone/core/session/session.py", line 638, in color_scheme
    self._client.send_event(SetColorScheme.from_odm(color_scheme))
  File "/opt/conda/lib/python3.11/site-packages/fiftyone/core/session/client.py", line 154, in send_event
    self._post_event(event)
  File "/opt/conda/lib/python3.11/site-packages/fiftyone/core/session/client.py", line 203, in _post_event
    raise RuntimeError(
RuntimeError: Failed to post event `set_color_scheme` to http://0.0.0.0:5151/event
```

### Code to reproduce issue


```python
import fiftyone as fo
session = fo.launch_app(fo.Dataset())
session.color_scheme = fo.ColorScheme()
```

### System information

-   **OS Platform and Distribution**: Linux Ubuntu 22.04
-   **Python version** (`python --version`): 3.11.7
-   **FiftyOne version** (`fiftyone --version`): 0.23.4
-   **FiftyOne installed from** (pip or source): pip

### Other info/logs

```python
Python 3.11.7 | packaged by conda-forge | (main, Dec 23 2023, 14:43:09) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fiftyone as fo
Migrating database to v0.23.4
>>> fo.delete_non_persistent_datasets()
>>> fo.list_datasets()
[]
>>> session = fo.launch_app(fo.Dataset())
App launched. Point your web browser to http://localhost:5151
>>> session.color_scheme = fo.ColorScheme()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.11/site-packages/fiftyone/core/session/session.py", line 638, in color_scheme
    self._client.send_event(SetColorScheme.from_odm(color_scheme))
  File "/opt/conda/lib/python3.11/site-packages/fiftyone/core/session/client.py", line 154, in send_event
    self._post_event(event)
  File "/opt/conda/lib/python3.11/site-packages/fiftyone/core/session/client.py", line 203, in _post_event
    raise RuntimeError(
RuntimeError: Failed to post event `set_color_scheme` to http://0.0.0.0:5151/event
```

### Willingness to contribute

The FiftyOne Community encourages bug fix contributions. Would you or another
member of your organization be willing to contribute a fix for this bug to the
FiftyOne codebase?

-   [ ] Yes. I can contribute a fix for this bug independently
-   [ ] Yes. I would be willing to contribute a fix for this bug with guidance
        from the FiftyOne community
-   [x] No. I cannot contribute a bug fix at this time



Discussion:

Resolving patch:
diff --git a/fiftyone/core/odm/dataset.py b/fiftyone/core/odm/dataset.py
--- a/fiftyone/core/odm/dataset.py
+++ b/fiftyone/core/odm/dataset.py
@@ -313,7 +313,7 @@ def to_dict(self, extended=False):
     @classmethod
     def from_dict(cls, d):
         d = dict(**d)
-        d["_id"] = ObjectId(d["id"])
+        d["_id"] = ObjectId(d.get("id", None))
         return super().from_dict(d)
 
 


Test patch:
diff --git a/tests/unittests/odm_tests.py b/tests/unittests/odm_tests.py
new file mode 100644
--- /dev/null
+++ b/tests/unittests/odm_tests.py
@@ -0,0 +1,21 @@
+"""
+FiftyOne odm unit tests.
+
+| Copyright 2017-2024, Voxel51, Inc.
+| `voxel51.com <https://voxel51.com/>`_
+|
+"""
+import unittest
+
+from bson import ObjectId
+
+import fiftyone as fo
+
+
+class ColorSchemeTests(unittest.TestCase):
+    def test_color_scheme_serialization(self):
+        color_scheme = fo.ColorScheme.from_dict({})
+        self.assertIsInstance(color_scheme.id, str)
+
+        d = fo.ColorScheme().to_dict()
+        self.assertIsInstance(d["id"], str)