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

Import Products populate script: Improve error message #1926

Closed
aliasifk opened this issue Dec 8, 2022 · 5 comments
Closed

Import Products populate script: Improve error message #1926

aliasifk opened this issue Dec 8, 2022 · 5 comments
Assignees
Labels
P4: low Non-critical, workarounds exist type: bug 🐛 Something isn't working
Milestone

Comments

@aliasifk
Copy link

aliasifk commented Dec 8, 2022

Describe the bug
While importing the products, it imports 0 products and logs this error in vendure-import-error.log
Cannot read properties of undefined (reading 'id')

A thing I observed is it uploads facets from the first row of CSV and then it throws error

To Reproduce
Steps to reproduce the behavior:

  1. Delete the DB
    my-migration-4.zip

  2. Create vendure.sqlite file

  3. Run the migration script which prepares a blank vendure database

  4. Run the populate scripts and upload the csv

Expected behavior

info 12/8/22, 8:35 PM - [Populate] Populated initial data

info 12/8/22, 8:35 PM - [Populate] Imported 50 products
info 12/8/22, 8:35 PM - [Populate] Done!

Environment (please complete the following information):

  • @vendure/core version:1.7.4
  • Nodejs version:16.17.0
  • Database (mysql/postgres etc): sqlite

Additional context
Before deleting the database, I tried uploading products to an existing database which consisted of products and it successfully imported all the products

an example set of my csv:

"Organza print with sequins & thread work
 Colour : Placid blue","organza-print-with-sequins-thread-work
-colour-placid-blue",,,color:blue|weave:organza|print:digital prints|work:sequins work|work:sequence work|tag:sabyasachi|tag:sabhyasachi,,,DPE12M-001-601,520,,,18,,,44,38,520
"Organza print with sequins & thread work
 Colour : Peach pie","organza-print-with-sequins-thread-work
-colour-peach-pie",,,color:peach|weave:organza|print:digital prints|work:sequins work|work:sequence work|tag:sabyasachi|tag:sabhyasachi,,,DPE12M-002-602,520,,,18,,,44,38,520
"Organza print with sequins & thread work
 Colour : Parrot green with royal blue","organza-print-with-sequins-thread-work
-colour-parrot-green-with-royal-blue",,,color:green|color:blue|weave:organza|print:digital prints|work:sequins work|work:sequence work|tag:sabyasachi|tag:sabhyasachi,,,DPE12M-003-603,520,,,18,,,44,38,520```

populate.ts

```import { bootstrap, DefaultJobQueuePlugin } from "@vendure/core";
import { populate } from "@vendure/core/cli";

import { config } from "../src/vendure-config";
import { initialData } from "./initial-data";

const path = require("path");

const productsCsvFile = path.join(__dirname, "./products-without-assets.csv");
const populateConfig = {
  ...config,
  plugins: (config.plugins || []).filter(
    // Remove your JobQueuePlugin during populating to avoid
    // generating lots of unnecessary jobs as the Collections get created.
    (plugin) => plugin !== DefaultJobQueuePlugin
  ),
};

populate(() => bootstrap(config), initialData, productsCsvFile)
  .then((app) => {
    return app.close();
  })
  .then(
    () => process.exit(0),
    (err) => {
      console.log(err);
      process.exit(1);
    }
  )
  .catch((e) => console.log(e));

initial-data.ts


import { InitialData, LanguageCode, Permission } from "@vendure/core";

export const initialData: InitialData = {
  paymentMethods: [],
  roles: [],
  defaultLanguage: LanguageCode.en,
  countries: [{ name: "India", code: "IN", zone: "Asia" }],
  defaultZone: "Asia",
  taxRates: [],
  shippingMethods: [],
  collections: [],
};



@aliasifk aliasifk added the type: bug 🐛 Something isn't working label Dec 8, 2022
@aliasifk
Copy link
Author

aliasifk commented Dec 9, 2022

Quick update I used this CSV from docs
https://github.com/vendure-ecommerce/vendure/blob/master/packages/core/mock-data/data-sources/products.csv

But still it shows same error:
Cannot read properties of undefined (reading 'id')

@aliasifk
Copy link
Author

aliasifk commented Dec 10, 2022

@michaelbromley I have found the bug after hours of debugging, The importer was not able to createProductVariant because there were no taxCategories.

Reason being:

export const initialData: InitialData = {
  paymentMethods: [],
  roles: [],
  defaultLanguage: LanguageCode.en,
  countries: [{ name: "India", code: "IN", zone: "Asia" }],
  defaultZone: "Asia",
  taxRates: [],
  shippingMethods: [],
  collections: [],
};

That empty taxRates Array was the problem all ALONG, it now works as expected

@michaelbromley
Copy link
Member

Thanks for the update. Do you happen to have a stack trace to go with this error?

Cannot read properties of undefined (reading 'id')

If so, I'd like to add a check here and give a more helpful error message to prevent others from getting stuck too.

@aliasifk
Copy link
Author

@michaelbromley I dont think there was any stack trace it was just

info 12/6/22, 9:49 PM - [Populate] Populated initial data
info 12/6/22, 9:49 PM - [Populate] Imported 0 products
error 12/6/2, 9:49 PM - [Populate] An error occured which was logged in vendure-import.log
info 12/6/22, 9:49 PM - [Populate] Done!

@michaelbromley
Copy link
Member

OK thanks. I'm going to re-open this because I think we need to provide a better error message which exactly states why the error is occurring.

@michaelbromley michaelbromley changed the title Import Products populate script Import Products populate script: Improve error message Dec 19, 2022
@dlhck dlhck moved this from 📅 Planned to 📦 Backlog in Vendure OS Roadmap Sep 24, 2024
@dlhck dlhck added the P4: low Non-critical, workarounds exist label Sep 24, 2024
@dlhck dlhck added this to the v3.0.5 milestone Sep 27, 2024
@michaelbromley michaelbromley moved this from 📦 Backlog to 💯 Ready in Vendure OS Roadmap Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4: low Non-critical, workarounds exist type: bug 🐛 Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants