diff --git a/sandbox/grist/objtypes.py b/sandbox/grist/objtypes.py index 569fb0c3..807633a7 100644 --- a/sandbox/grist/objtypes.py +++ b/sandbox/grist/objtypes.py @@ -183,7 +183,7 @@ def encode_object(value): return ['d', moment.date_to_ts(value)] elif isinstance(value, RaisedException): return ['E'] + value.encode_args() - elif isinstance(value, (list, tuple, RecordList, records.ColumnView)): + elif isinstance(value, (list, tuple, RecordList)): return ['L'] + [encode_object(item) for item in value] elif isinstance(value, records.RecordSet): # Represent RecordSet (e.g. result of lookupRecords) in the same way as a RecordList. diff --git a/sandbox/grist/records.py b/sandbox/grist/records.py index c6af60c5..39da0168 100644 --- a/sandbox/grist/records.py +++ b/sandbox/grist/records.py @@ -192,31 +192,6 @@ class RecordSet(object): sort_by=self._sort_by) -class ColumnView(object): - """ - ColumnView is an iterable that represents one column of a RecordSet. You may iterate through - its values and see its size, but it provides no other interface. - """ - def __init__(self, column_obj, row_ids, relation): - self._column = column_obj - self._row_ids = row_ids - self._source_relation = relation - - def __len__(self): - return len(self._row_ids) - - def __iter__(self): - for row_id in self._row_ids: - yield adjust_record(self._source_relation, self._column.get_cell_value(row_id)) - - def __eq__(self, other): - return (isinstance(other, ColumnView) and - (self._column, self._row_ids) == (other._column, other._row_ids)) - - def __ne__(self, other): - return not self.__eq__(other) - - def adjust_record(relation, value): """ Helper to adjust a Record's source relation to be the composition with the given relation. This diff --git a/sandbox/grist/table.py b/sandbox/grist/table.py index 14684b11..975da063 100644 --- a/sandbox/grist/table.py +++ b/sandbox/grist/table.py @@ -547,26 +547,19 @@ class Table(object): # TODO: document everything here. - def _use_column(self, col_id, relation, row_ids): - """ - relation - Describes how the record was obtained, on which col_id is being accessed. - """ - col = self.all_columns[col_id] - # The _use_node call both creates a dependency and brings formula columns up-to-date. - self._engine._use_node(col.node, relation, row_ids) - return col - # Called when record.foo is accessed def _get_col_value(self, col_id, row_id, relation): - return records.adjust_record(relation, - self._use_column(col_id, relation, [row_id]).get_cell_value(row_id)) + [value] = self._get_col_subset(col_id, [row_id], relation) + return value def _attribute_error(self, col_id, relation): self._engine._use_node(self._new_columns_node, relation) raise AttributeError("Table '%s' has no column '%s'" % (self.table_id, col_id)) - # Called when record_set.foo is accessed. Should return something like a ColumnView. + # Called when record_set.foo is accessed def _get_col_subset(self, col_id, row_ids, relation): - # TODO: when column is a reference, we ought to return RecordSet. Otherwise ColumnView - # looks like a RecordSet (returns Records), but doesn't support property access. - return records.ColumnView(self._use_column(col_id, relation, row_ids), row_ids, relation) + col = self.all_columns[col_id] + # creates a dependency and brings formula columns up-to-date. + self._engine._use_node(col.node, relation, row_ids) + # TODO: when column is a reference, support property access in return value + return [records.adjust_record(relation, col.get_cell_value(row_id)) for row_id in row_ids] diff --git a/sandbox/grist/test_renames.py b/sandbox/grist/test_renames.py index 81a275ce..1e18cfb6 100644 --- a/sandbox/grist/test_renames.py +++ b/sandbox/grist/test_renames.py @@ -226,13 +226,6 @@ class TestRenames(test_engine.EngineTestCase): "People.lookupOne(addr=$id, city=$city).nombre", "People.lookupRecords(addr=$id).nombre"] }], - # TODO This is a symptom of comparing before and after values using rich values that refer - # to a destroyed column (a ColumnView). In reality, the values before and after after the - # same, but here the attempt to encode the previous value produces an incorrect result. - # (It's a bug, but not easy to fix and hopefully hard to run into.) - ["BulkUpdateRecord", "Address", [11, 12, 13], - {"people2": [["L", "Sam"], ["L", "Bob", "Doug"], ["L", "Alice"]] - }], ]}) def test_rename_lookup_ref_attr(self):