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!

Hello @arnaudambro,

Thanks for your message shared in private!

Could you please try to upgrade the agent forest-express-mongoose to the latest version and see if the issue persists?

Thanks :pray:

"forest-express-mongoose": "^7.9.2"

still the exact same…

Could you try with the 8.4.3?

still the same

here are my deps

 "dependencies": {
    "@sentry/node": "^5.23.0",
    "aws-sdk": "^2.832.0",
    "bcrypt": "^5.0.0",
    "chalk": "~1.1.3",
    "cookie-parser": "1.4.4",
    "cors": "2.8.5",
    "debug": "~4.0.1",
    "dotenv": "~6.1.0",
    "express": "4.17.1",
    "express-jwt": "^6.1.0",
    "firebase-admin": "^9.4.2",
    "forest-express-mongoose": "^8.4.3",
    "form-data": "^4.0.0",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^6.0.12",
    "morgan": "1.9.1",
    "node-fetch": "^2.6.1",
    "node-schedule": "^1.3.2",
    "npm": "^8.0.0",
    "require-all": "^3.0.0",
    "urijs": "^1.19.6"
  }

Hello @arnaudambro,

I know this ticket is quite old, I don’t know if you still have the issue on your project.
I’ve never been able to reproduce, but I just came on another ticket that might be linked to your issue.

Could you tell me if the collection where you have the problem is ordered by a non-unique field?

Thanks a lot.