mirror of
				https://github.com/gristlabs/grist-core.git
				synced 2025-06-13 20:53:59 +00:00 
			
		
		
		
	(core) Fix bug in data engine when records are added after clearing a table with ReplaceTableData.
Summary: It was manifesting as error "docactions.[Bulk]UpdateRecord for non-existent record #1", and due to manualSort column having internal state that wasn't properly cleared. Test Plan: Added a test case that fails without the fix. Reviewers: georgegevoian Reviewed By: georgegevoian Subscribers: georgegevoian Differential Revision: https://phab.getgrist.com/D4183
This commit is contained in:
		
							parent
							
								
									fe2089710e
								
							
						
					
					
						commit
						b64802dfe8
					
				| @ -358,6 +358,10 @@ class PositionColumn(NumericColumn): | ||||
|     # This is a list of row_ids, ordered by the position. | ||||
|     self._sorted_rows = SortedListWithKey(key=lambda x: SafeSortKey(self.raw_get(x))) | ||||
| 
 | ||||
|   def clear(self): | ||||
|     super(PositionColumn, self).clear() | ||||
|     self._sorted_rows.clear() | ||||
| 
 | ||||
|   def set(self, row_id, value): | ||||
|     self._sorted_rows.discard(row_id) | ||||
|     super(PositionColumn, self).set(row_id, value) | ||||
|  | ||||
							
								
								
									
										47
									
								
								sandbox/grist/test_replace_table_data.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								sandbox/grist/test_replace_table_data.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,47 @@ | ||||
| import logging | ||||
| 
 | ||||
| import test_engine | ||||
| from test_engine import Table, Column | ||||
| 
 | ||||
| log = logging.getLogger(__name__) | ||||
| 
 | ||||
| class TestReplaceTableData(test_engine.EngineTestCase): | ||||
| 
 | ||||
|   @test_engine.test_undo | ||||
|   def test_replace_and_add(self): | ||||
|     # This tests a fix for a bug where after ReplaceTableData, subsequent adds were causing an | ||||
|     # error with "relabeling" (updating manualSort column). | ||||
| 
 | ||||
|     # Add a table with a couple of columns and records. | ||||
|     self.apply_user_action(["AddTable", "Vessels", []]) | ||||
|     self.apply_user_action(["AddColumn", "Vessels", "Type", {}]) | ||||
|     self.apply_user_action(["AddColumn", "Vessels", "Size", {}]) | ||||
|     self.apply_user_action(["BulkAddRecord", "Vessels", [None, None], | ||||
|       {"Type": ["cup", "pot"], "Size": [8, 64]}]) | ||||
| 
 | ||||
|     # Check that we guessed correct column types, and the values are there. | ||||
|     self.assertTables([ | ||||
|       Table(1, "Vessels", primaryViewId=1, summarySourceTable=0, columns=[ | ||||
|         Column(1, "manualSort", "ManualSortPos",  False, "", 0), | ||||
|         Column(2, "Type",       "Text",           False, "", 0), | ||||
|         Column(3, "Size",       "Numeric",        False, "", 0), | ||||
|       ]) | ||||
|     ]) | ||||
|     self.assertTableData("Vessels", cols="subset", rows="all", data=[ | ||||
|       [ "id", "Type", "Size"  ], | ||||
|       [ 1,    "cup",     8    ], | ||||
|       [ 2,    "pot",    64    ], | ||||
|     ]) | ||||
| 
 | ||||
|     # Now do ReplaceTableData, and add more rows. | ||||
|     self.apply_user_action(["ReplaceTableData", "Vessels", [], {}]) | ||||
| 
 | ||||
|     # The bug used to happen here, manifesting as error | ||||
|     # "docactions.[Bulk]UpdateRecord for non-existent # record #1" | ||||
|     self.apply_user_action(["BulkAddRecord", "Vessels", [None, None], | ||||
|       {"Type": ["shot", "bucket"], "Size": [1.5, 640.0]}]) | ||||
|     self.assertTableData("Vessels", cols="subset", rows="all", data=[ | ||||
|       [ "id", "Type",   "Size"  ], | ||||
|       [ 1,    "shot",     1.5   ], | ||||
|       [ 2,    "bucket",   640   ], | ||||
|     ]) | ||||
| @ -2824,9 +2824,12 @@ export async function onNewTab(action: () => Promise<void>) { | ||||
|   await driver.executeScript("window.open('about:blank', '_blank')"); | ||||
|   const tabs = await driver.getAllWindowHandles(); | ||||
|   await driver.switchTo().window(tabs[tabs.length - 1]); | ||||
|   await action(); | ||||
|   await driver.close(); | ||||
|   await driver.switchTo().window(tabs[tabs.length - 2]); | ||||
|   try { | ||||
|     await action(); | ||||
|   } finally { | ||||
|     await driver.close(); | ||||
|     await driver.switchTo().window(tabs[tabs.length - 2]); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user