Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Sync actions fail with error on an undefined field

Aperta
#1,545 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, nodejs
Ambito
api, backend

Direzione di ricerca

Inizia riproducendo il caso di sincronizzazione del cliente e ispeziona packages/data-import/dist/lib/sync.js insieme agli stack frame di sync-actions in buildArrayActions e actionsMapAddresses. Il lavoro è completato quando lo stesso payload non genera più un'eccezione se proprietà come addresses o shippingAddressIds sono undefined e le actions risultanti seguono il comportamento indicato di ignorare o usare un array vuoto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

I was wondering what is expected behaviour from commercetools nodejs sdk perspective in the following scenario:

  1. Create a customer:
{
  "key": "abc",
  "email": "[email protected]",
  "password": "password"
}
  1. Use sync actions using the same payload:
{
  "key": "abc",
  "email": "[email protected]",
  "password": "password"
}

It fails with an error:

TypeError: Cannot read property '0' of undefined
    at /node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:496:73
    at Array.forEach (<anonymous>)
    at buildArrayActions (/node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:484:31)
    at actionsMapAddresses (/node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:906:10)
    at /node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:951:14
    at mapActionGroup (/node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:264:51)
    at doMapActions (/node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:950:21)
    at Object.buildActions (/node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:250:12)
    at /packages/data-import/dist/lib/sync.js:37:33
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

It looks like sync actions fail to merge arrays when the new resource does not have a property defined. In the case of the customer type when a customer is created following properties are defined with empty array addresses, shippingAddressIds, billingAddressIds and stores.

Expected Behavior

Sync actions to skip a property for new resource when old resource has empty array and the property is not defined.

Alternatively, add the property with empty array which enables sync actions to resolve actions accordingly. (probably easier)

Current Behavior

Throws an error.

Possible Solution

I'm happy to create PR if that is expected behaviour.

Lingua principale
JavaScript
Stelle
78
Fork
70
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di commercetools/nodejs

Tutte le issue di commercetools/nodejs

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.