Bug with "Select current page only" + smart action

Expected behavior

I have a smart segment, with 126 items inside
I wanted to do a smart action for each of them, I clicked on the checkbox on top of the checkbox column, and I triggered my smart action.
Then I realised I did the smart action on the current page only, so I did the same stuff on pages 2 then 3 then 4 of my segment

The smart action was about sending a SMS to each user of my segment, and some of them told me “hey ! I received 4 times your SMS !”

Then I checked, and indeed, some of the ids I received with new RecordsGetter(User).getIdsFromRequest(req); on pages 2-3-4 were already on page 1.

[EDIT] it’s the actual pagination which is broken

Actual behavior

Working correctly !

Failure Logs

Please include any relevant log snippets, if necessary.

Context

Please provide any relevant information about your setup.

  • Package Version: “forest-express-mongoose”: “^7.6.0”,
  • Express Version: “express”: “4.17.1”,
  • Sequelize Version:
  • Database Dialect:
  • Database Version:
  • Project Name: can say on MP

Hey @arnaudambro!

Thanks for your message :raised_hands:

That’s very not cool, let’s investigate what’s going on here.
Could you please tell me:

  • What is your smart action type (bulk, global or simple)?
  • Is this smart action defined on a regular collection or on smart collection?
  • You said that some of the ids you received on pages 2-3-4 were already on page 1. So not all of them? Does it look random to you?
  • Apparently you have identified an issue with the current pagination, would you mind sharing what you discovered?

Thanks!

PS: Do you know that you can select all the records (all pages - not only the current one)?

Yes, I told my client to select all the records to avoid mistakes, but still

  • the smart action is bulk
  • it’s defined on a regular collection (I didn’t know we could create a smart collection)
  • it looks random, although it’s always the same results
  • no idea how it could bug !

For your investigation,

my smart segment is:

    {
      name: 'CESTCADEAU5 Sélection',
      where: async () => {
        const users = await User.find({ arrayField: 'CESTCADEAU5' });
        const userIds = users.map((u) => u._id);
        return { _id: { $in: userIds } };
      },
    },

my smart action

      name: 'Send Test SMS',
      type: 'bulk',
      fields: [
        {
          field: 'text',
          isRequired: true,
          description: 'What do you want to say ?',
          type: 'string',
        },
      ],
    },

my smart action route

// Send SMS text message
router.post('/actions/send-test-sms', permissionMiddlewareCreator.smartAction(), async (req, res) => {
  try {
    const { text } = req.body.data.attributes.values;
    const userIds = await new RecordsGetter(User).getIdsFromRequest(req);
    const users = await User.find({ _id: userIds });

    for (let user of users) {
      await sendSms(user.phone, text, user._id);
    }

    res.status(200).send({
      success: users.length > 1 ? `SMS sent to ${users.length} users !` : 'SMS sent !',
    });
});

@arnaudambro,

Thanks for the elements.
Unfortunately, I was not able to reproduce this problem.

Could you please share with me:

  • a screenshot with the collection current page, and the smart action payload (with the ids displayed) → we might see the diff here

  • the result on the server side of userIds = await new RecordsGetter(user).getIdsFromRequest(req);

Many thanks!

Hello @arnaudambro,

Any news on this subject?

Thanks!