Skip to content

Commit 14236aa

Browse files
committed
fix(MetadataStore): edge case where the meta is empty with invalid keys
1 parent 36f0ce0 commit 14236aa

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/onnx_ir/_core_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4139,6 +4139,19 @@ def test_deep_clone_graph_meta(self):
41394139
self.assertTrue(cloned_graph.meta.is_valid("valid_key"))
41404140
self.assertFalse(cloned_graph.meta.is_valid("invalid_key"))
41414141

4142+
@parameterized.parameterized.expand([(True,), (False,)])
4143+
def test_clone_graph_empty_meta_with_only_invalid_keys(self, deep_copy):
4144+
"""Test cloning a graph with empty meta that has only invalid keys."""
4145+
v0 = _core.Value(name="input")
4146+
node = _core.Node("", "Identity", inputs=(v0,), num_outputs=1)
4147+
graph = _core.Graph(inputs=(v0,), outputs=(node.outputs[0],), nodes=(node,))
4148+
graph.meta.invalidate("invalid_key")
4149+
4150+
cloned_graph = graph.clone(deep_copy=deep_copy)
4151+
4152+
# Check validity
4153+
self.assertFalse(cloned_graph.meta.is_valid("invalid_key"))
4154+
41424155
def test_clone_preserves_node_attributes(self):
41434156
"""Test that cloning preserves node attributes."""
41444157
v0 = _core.Value(name="input")

src/onnx_ir/_metadata.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ def is_valid(self, key: str) -> bool:
4343

4444
def __repr__(self) -> str:
4545
return f"{self.__class__.__name__}({self.data!r}, invalid_keys={self._invalid_keys!r})"
46+
47+
def __bool__(self) -> bool:
48+
return bool(self.data) or bool(self._invalid_keys)

0 commit comments

Comments
 (0)