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

Loading products using process function does not stop

Aperta
#166 1 commento 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

Direzione di ricerca

Inizia dal punto di ingresso products.perPage(PER_PAGE).process(...) mostrato nella riproduzione e traccia il modo in cui vengono richiesti i batch dopo che il callback di processo modifica res.body.results. Riproduci il problema con i conteggi dei prodotti indicati e la rimozione di item.id; il lavoro è completato quando l’elaborazione si interrompe dopo tutti i prodotti e viene eseguito il completion handler finale.

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

Descrizione

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);
  });

Lingua principale
CoffeeScript
Stelle
16
Fork
8
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/sphere-node-sdk

Tutte le issue di commercetools/sphere-node-sdk

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.