Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Loading products using process function does not stop

オープン
#166 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, nodejs
領域
api

調査の方向性

再現例に示されているエントリーポイント products.perPage(PER_PAGE).process(...) から開始し、process callback が res.body.results を変更した後にバッチがどのように要求されるかを追跡します。指定された商品数と item.id の削除で再現します; すべての商品を処理した後に処理が停止し、最後の completion handler が実行されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Expected behavior

Function sphere.products.perPage(50).process(function process(res){}) should load products in batches and send them to process function.

Actual behavior

If I add this code to process function, loading will never stop.

var list = res.body.results;
list = list.map(function (item) {
  delete item.id;  // when commented out - loading works as expected
  return item;
});
Steps to reproduce the behavior

I was testing it on:

  • project with 639 products and perPage = 50
  • project with 1 product and perPage = 1

It looks like it occurs when perPage <= productCount
Here is full code which gives me an error.

var _ = require('lodash');
var Promise = require('bluebird');
var Sphere = require('sphere-node-sdk');
var SphereUtils = require('sphere-node-utils');
var SphereClient = Sphere.SphereClient;

var ProjectCredentialsConfig = SphereUtils.ProjectCredentialsConfig;
var sourceCredentials, sourceClient;

var PER_PAGE = 50;

var projectKey = "<product-key>";
var total = 0;
console.log('>> Loading products from %s', projectKey);
ProjectCredentialsConfig.create()
  .then(function (credentials) {
    sourceCredentials = credentials.enrichCredentials({project_key: projectKey});
    sourceClient = new SphereClient({config: sourceCredentials});

    console.log("Loading per page %d", PER_PAGE);
    var total = 0;
    return sourceClient.products
      .perPage(PER_PAGE)
      .process(function(res) {
        var list = res.body.results;
        total += list.length;

        console.log('Loaded %d / totally %d', list.length, total);

        list = list.map(function (item) {
          delete item.id;  // when commented out - loading works as expected
          return item;
        });
        return Promise.resolve();
    })
  })
  .then(function() {
    console.log("Finished - total %d", total);
  })
  .catch(function (err) {
    console.error("Final error:", err.stack || err);
  });

主要言語
CoffeeScript
スター
16
フォーク
8
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

commercetools/sphere-node-sdk のほかの issue

commercetools/sphere-node-sdk の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。