(core) Fix undo of Ref->Numeric conversion.

Test Plan: Added a test case that reproduces the bug and tests the fix

Reviewers: alexmojaki

Reviewed By: alexmojaki

Subscribers: alexmojaki

Differential Revision: https://phab.getgrist.com/D4057
pull/686/head
Dmitry S 8 months ago
parent cce185956c
commit 6a3f50d77e

@ -495,6 +495,14 @@ class ReferenceColumn(BaseReferenceColumn):
if new_value:
self._relation.add_reference(row_id, new_value)
def set(self, row_id, value):
# Allow float values that are small integers. In practice, this only turns out to be relevant
# in rare cases (such as undo of Ref->Numeric conversion).
if type(value) == float and value.is_integer(): # pylint:disable=unidiomatic-typecheck
if value > 0 and objtypes.is_int_short(int(value)):
value = int(value)
super(ReferenceColumn, self).set(row_id, value)
def prepare_new_values(self, values, ignore_data=False, action_summary=None):
if action_summary and values:
values = action_summary.translate_new_row_ids(self._target_table.table_id, values)

@ -0,0 +1,53 @@
import {assert, driver} from 'mocha-webdriver';
import * as gu from 'test/nbrowser/gristUtils';
import {setupTestSuite} from 'test/nbrowser/testUtils';
describe('RefNumericChange', function() {
this.timeout(20000);
const cleanup = setupTestSuite();
afterEach(() => gu.checkForErrors());
it('should allow converting a ref column to numeric and undoing it', async function() {
// We had a bug with Ref -> Numeric conversion when starting with a Ref column that showed a
// numeric display col.
const session = await gu.session().teamSite.user('user1').login();
const docId = (await session.tempNewDoc(cleanup, 'RefNumericChange1', {load: false}));
const api = session.createHomeApi();
await api.applyUserActions(docId, [
['AddTable', 'TestTable', [{id: 'Num', type: 'Numeric'}, {id: 'Ref', type: 'Ref:TestTable'}]],
['BulkAddRecord', 'TestTable', [null, null, null, null], {Num: ['5', '10', '15'], Ref: [3, 2, 0, '17.0']}],
]);
await session.loadDoc(`/doc/${docId}/p/2`);
// Change TestTable.Ref column (of type Ref:TestTable) to use TestTable.Num as "SHOW COLUMN".
await gu.getCell({section: 'TestTable', rowNum: 1, col: 'Ref'}).click();
await gu.toggleSidePanel('right', 'open');
await driver.find('.test-right-tab-field').click();
await driver.find('.test-fbuilder-ref-col-select').click();
await driver.findContent('.test-select-row', /Num/).click();
await gu.waitForServer();
assert.equal(await driver.find('.test-fbuilder-type-select').getText(), "Reference");
assert.deepEqual(await gu.getVisibleGridCells({section: 'TestTable', rowNums: [1, 2, 3, 4], col: 'Ref'}),
['15', '10', '', '17.0']);
// Change type of column Ref to Numeric.
await gu.getCell({section: 'TestTable', rowNum: 1, col: 'Ref'}).click();
await gu.setType('Numeric');
await driver.findContent('.type_transform_prompt button', /Apply/).click();
await gu.waitForServer();
await gu.checkForErrors();
assert.equal(await driver.find('.test-fbuilder-type-select').getText(), "Numeric");
assert.deepEqual(await gu.getVisibleGridCells({section: 'TestTable', rowNums: [1, 2, 3, 4], col: 'Ref'}),
['15', '10', '0', '17']);
// Revert.
await gu.undo();
assert.equal(await driver.find('.test-fbuilder-type-select').getText(), "Reference");
assert.deepEqual(await gu.getVisibleGridCells({section: 'TestTable', rowNums: [1, 2, 3, 4], col: 'Ref'}),
['15', '10', '', '17.0']);
});
});
Loading…
Cancel
Save