Repository: equinor/fmu-dataio

Issue:
Fix bug in compute_md5_from_objdata
All objects cause an exception in `ObjectDataProvider.compute_md5`: `NameError: name 'BytesIO' is not defined` 

'BytesIO' is only imported under TYPE_CHECKING in the objdataprovider, hence this bug have gone under the radar. It needs to be a standard import.

https://github.com/equinor/fmu-dataio/blob/de513340cd94ed265647db816af71adf6d127888/src/fmu/dataio/_utils.py#L180-L189

Discussion:

Solution patch:
diff --git a/src/fmu/dataio/providers/objectdata/_base.py b/src/fmu/dataio/providers/objectdata/_base.py
index c3bcb74db..7f80a69c0 100644
--- a/src/fmu/dataio/providers/objectdata/_base.py
+++ b/src/fmu/dataio/providers/objectdata/_base.py
@@ -4,6 +4,7 @@ import warnings
 from abc import abstractmethod
 from dataclasses import dataclass, field
 from datetime import datetime
+from io import BytesIO
 from pathlib import Path
 from tempfile import NamedTemporaryFile
 from typing import TYPE_CHECKING, Any, Final
@@ -28,9 +29,6 @@ from fmu.dataio.providers.objectdata._export_models import (
 )
 
 if TYPE_CHECKING:
-    from io import BytesIO
-    from pathlib import Path
-
     from pydantic import BaseModel
 
     from fmu.dataio._models.fmu_results.data import (
diff --git a/src/fmu/dataio/providers/objectdata/_provider.py b/src/fmu/dataio/providers/objectdata/_provider.py
index 11410a145..27f65eed6 100644
--- a/src/fmu/dataio/providers/objectdata/_provider.py
+++ b/src/fmu/dataio/providers/objectdata/_provider.py
@@ -117,7 +117,6 @@ from ._xtgeo import (
 
 if TYPE_CHECKING:
     from io import BytesIO
-    from pathlib import Path
 
     from fmu.dataio.dataio import ExportData
     from fmu.dataio.types import Inferrable


Test patch:
diff --git a/tests/test_units/test_objectdataprovider_class.py b/tests/test_units/test_objectdataprovider_class.py
index 861faca72..c81d4974d 100644
--- a/tests/test_units/test_objectdataprovider_class.py
+++ b/tests/test_units/test_objectdataprovider_class.py
@@ -170,3 +170,12 @@ def test_regsurf_preprocessed_observation(
     with open(out.parent / f".{out.name}.yml", encoding="utf-8") as f:
         metadata = yaml.safe_load(f)
     assert metadata["data"] == case_meta["data"]
+
+
+def test_objectdata_compute_md5(gridproperty, edataobj1):
+    """Test compute_md5 function works and gives same result as in the metadata"""
+
+    myobj = objectdata_provider_factory(gridproperty, edataobj1)
+
+    metadata = edataobj1.generate_metadata(gridproperty)
+    assert metadata["file"]["checksum_md5"] == myobj.compute_md5()