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

[front] fix(csv) - csv parsing #9121

Merged
merged 8 commits into from
Dec 4, 2024
4 changes: 2 additions & 2 deletions front/lib/api/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,14 @@ export async function rowsFromCsv({

let i = 0;
const parser = parse(csv, { delimiter });
const valuesByCol: Record<string, string[]> = {};
const valuesByCol: Record<string, string[]> = Object.create(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain a bit more? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mb completely forgot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here it was {}["constructor"] that caused the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@aubin-tchoi aubin-tchoi Dec 4, 2024

Choose a reason for hiding this comment

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

@spolu added a comment in code to explain the Object.create(null)

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

for await (const anyRecord of parser) {
if (i++ >= rowIndex) {
const record = anyRecord as string[];
for (const [i, h] of header.entries()) {
try {
valuesByCol[h] ??= [];
(valuesByCol[h] as string[]).push(record[i] || "");
(valuesByCol[h] as string[]).push(record[i] ?? "");
Copy link
Contributor

Choose a reason for hiding this comment

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

What types of value are we going to get that we didn't get? Are they desirable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this change is preemptive and not related to the fix, here if we get a value of 0 in record[i] it gets converted to ""

} catch (e) {
logger.error(
// temporary log to fix the valuesByCol[h].push is not a function error
Expand Down
Loading