From d9926b6e33c9935cc3c0eb2412d7d8c553cfcbe3 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 22 Nov 2026 08:20:32 +0000 Subject: [PATCH 1/2] TEST: A view of a Flow Data's Element Data adds with |=, and a finished Flow Data gives one view Three tests of the Element Data view fail today. An in-place union through a view raises TypeError, as the view has no such operator. A finished Flow Data gives a new view for each read, although nothing can be added to it. A removal from a finished Flow Data does not say that the Flow Data has finished processing. A fourth, which passes today, records that each read gives its own view while Element Data can still be added. --- .../tests/test_flowdata_element_data_list.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pipeline/fiftyone_pipeline_core/tests/test_flowdata_element_data_list.py b/pipeline/fiftyone_pipeline_core/tests/test_flowdata_element_data_list.py index 694a658a..9a8193d5 100644 --- a/pipeline/fiftyone_pipeline_core/tests/test_flowdata_element_data_list.py +++ b/pipeline/fiftyone_pipeline_core/tests/test_flowdata_element_data_list.py @@ -155,6 +155,40 @@ def test_a_write_through_a_view_shows_in_that_view(self): self.assertEqual(["first", "second", "third"], list(view)) self.assertIs(first, flowdata.get("first")) + def test_an_in_place_union_adds_through_a_view(self): + element = AddsItsData("one") + flowdata = pipeline(element).create_flowdata() + view = flowdata.data + added = ElementDataDictionary(element, {"name": "added"}) + + view |= {"added": added} + + self.assertIs(added, view["added"]) + self.assertIs(added, flowdata.get("added")) + + def test_each_read_gives_its_own_view_while_element_data_is_added(self): + flowdata = pipeline(AddsItsData("one")).create_flowdata() + + self.assertIsNot(flowdata.data, flowdata.data) + + def test_a_finished_flow_data_gives_the_same_view_each_time(self): + flowdata = pipeline(AddsItsData("one")).create_flowdata() + flowdata.process() + + self.assertIs(flowdata.data, flowdata.data) + + def test_a_removal_from_a_finished_flow_data_says_it_is_read_only(self): + flowdata = pipeline(AddsItsData("one")).create_flowdata() + with self.assertRaises(TypeError) as before: + del flowdata.data["one"] + flowdata.process() + with self.assertRaises(TypeError) as after: + del flowdata.data["one"] + + self.assertNotIn("finished processing", str(before.exception)) + self.assertIn("is not removed", str(after.exception)) + self.assertIn("finished processing", str(after.exception)) + def test_a_copy_is_a_dict_of_the_element_data(self): flowdata = pipeline( AddsItsData("one"), AddsItsData("two")).create_flowdata() From 07497d92e26aca39d6e68b243ed7356f3dafdb4e Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 22 Nov 2026 08:23:06 +0000 Subject: [PATCH 2/2] BUG: Refuse writes through a view of a finished Flow Data's Element Data A Flow Data is read only once processing has finished, and its Element Data is kept in a linked list read through views. The two did not meet: a view added to a finished Flow Data, and a replacement for the list was copied into a dict before the data property read it, so the property never called the mapping's own items(). A view now refuses to set a key once the Flow Data has finished, with the message every other write gives, and so update, setdefault and |= do too. |= is new, and adds as update does. A removal is still a TypeError, as Element Data is never removed, and says when the Flow Data has finished. Setting data passes the mapping given to the data property as it is, and only errors is kept in a dict that refuses writes. A finished Flow Data gives the same view for each read, as nothing can be added to it. While Element Data can be added, each read still gives a view of its own. --- .../src/fiftyone_pipeline_core/flowdata.py | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/flowdata.py b/pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/flowdata.py index b4f948c5..55b91ee7 100644 --- a/pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/flowdata.py +++ b/pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/flowdata.py @@ -66,6 +66,10 @@ class ElementDataView(MutableMapping): as it is after the add. Element Data is not removed, so del, pop, popitem and clear raise TypeError. copy gives a dict. + Once the FlowData has finished processing the view is read only, so + setting a key, update, setdefault and |= raise as a write to the + FlowData does. + Iteration gives each key once, in the order the keys were first added. While a Pipeline processes, each Flow Element adds its own in turn, so that is Pipeline order. Element Data added another way, such as before @@ -95,13 +99,29 @@ def __getitem__(self, key): raise KeyError(key) return node.element_data + def _finished(self): + # Read from the FlowData's own fields, because FlowData treats an + # attribute it does not have as the key of Element Data. + return self._flowdata.__dict__.get("processed") + def __setitem__(self, key, element_data): + if self._finished(): + raise Exception( + Messages.FLOW_DATA_FINISHED.format(_GIVEN["data"])) self._flowdata._add(key, element_data) # This view now shows the list with the add, as a mapping should. self._head = self._flowdata._head def __delitem__(self, key): - raise TypeError("Element Data is not removed from a FlowData") + message = "Element Data is not removed from a FlowData" + if self._finished(): + message += (". This FlowData has finished processing, so it " + "is read only") + raise TypeError(message) + + def __ior__(self, other): + self.update(other) + return self def __iter__(self): return iter(self._latest()) @@ -190,6 +210,8 @@ def __init__(self, pipeline): # The newest node of the Element Data list. See data. self._head = None + # The one view given once processing has finished. See data. + self._finished_view = None self.errors = {} self.pipeline = pipeline self.processed = False @@ -201,9 +223,10 @@ def __init__(self, pipeline): def __setattr__(self, name, value): """! - Set an attribute. The ElementData and errors are kept in dicts that - refuse writes once processing has finished, and they and the - Evidence cannot be replaced then. + Set an attribute. The errors are kept in a dict that refuses + writes once processing has finished, as the views of the + ElementData do, and neither they nor the Evidence can be replaced + then. @raise Exception: when one of them is set once processing has finished @@ -215,7 +238,9 @@ def __setattr__(self, name, value): if self.__dict__.get("processed"): raise Exception(Messages.FLOW_DATA_FINISHED.format( _GIVEN[name])) - if name != "evidence": + # The ElementData goes to the data property as it was given, + # which builds the list from it. + if name == "errors": value = _FlowDataDict(self, _GIVEN[name], value) object.__setattr__(self, name, value) @@ -443,9 +468,19 @@ def data(self): The Element Data in this FlowData, keyed by data key in lower case, as the list is now. Iteration gives Pipeline order. + Each read gives a view of its own while Element Data can still be + added. Once processing has finished nothing is added, so every + read gives the same view. + @rtype: ElementDataView """ + if self.__dict__.get("processed"): + view = self.__dict__.get("_finished_view") + if view is None: + view = ElementDataView(self, self._head) + self._finished_view = view + return view return ElementDataView(self, self._head) @data.setter