Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-issue]: Fix upserting dynamic columns #4226

Merged
merged 1 commit into from
Oct 17, 2022

Conversation

rohan-bes
Copy link
Collaborator

Issue https://beyondessential.slack.com/archives/C01MAA3NKM1/p1665977231627499:

This issue is a bit rare, but when we're using dynamic columns to override an existing column, the old values from the existing column are kept.

newColumns[columnName] = table.hasColumn(columnName)
? table.getColumnValues(columnName) // Upserting a column, so fill with current column values
: new Array(table.length()).fill(undefined); // Creating a new column, so fill with undefined
newColumns[columnName] = new Array(table.length()).fill(undefined);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we now re-insert the skipped rows, there's no need for the conditional upsert logic, just overwrite everything and let the skipped rows re-insert themselves if they exist.

Copy link
Contributor

@biaoli0 biaoli0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rohan-bes Thanks for adding the unit test and the fix! Just got a minor suggestion, but can pre approve.

@@ -51,7 +51,14 @@ const insertColumns = (table: TransformTable, params: InsertColumnsParams, conte
values,
}));

return table.upsertColumns(columnUpserts);
// Drop, then re-insert the original skipped rows
const rowsToDrop = Object.keys(skippedRows).map(rowIndexString => parseInt(rowIndexString));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const rowsToDrop = Object.keys(skippedRows).map(rowIndexString => parseInt(rowIndexString));
const rowsToDrop = Object.keys(skippedRows);

Should keys of skippedRows are number?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately even though we set them as numbers, they come out as strings. That's JS for you 🤷

@rohan-bes rohan-bes merged commit fc30fc5 into release-2022-42 Oct 17, 2022
@rohan-bes rohan-bes deleted the fix-upsert-dynamic-column branch October 17, 2022 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants