Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Sync actions fail with error on an undefined field

Đang mở
#1,545 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, nodejs
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện trường hợp đồng bộ hóa khách hàng và kiểm tra packages/data-import/dist/lib/sync.js cùng với các stack frame của sync-actions trong buildArrayActions và actionsMapAddresses. Hoàn tất có nghĩa là cùng payload đó không còn gây ra exception khi các thuộc tính như addresses hoặc shippingAddressIds là undefined, và các actions tạo ra tuân theo hành vi đã nêu là bỏ qua hoặc dùng một mảng rỗng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
JavaScript
Star
77
Fork
70
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của commercetools/nodejs

Tất cả issue của commercetools/nodejs

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.