Sails: Set unlimited records (MAX_SAFE_INTEGER) for Find in blueprint routes

Created on 31 May 2019  路  8Comments  路  Source: balderdashy/sails

Node version: 8.9.4
Sails version _(sails)_: 1.1.0
ORM hook version _(sails-hook-orm)_: 2.0.0.0-16
Sockets hook version _(sails-hook-sockets)_: 1.4.0
Organics hook version _(sails-hook-organics)_: NA
Grunt hook version _(sails-hook-grunt)_: 3.0.2
Uploads hook version _(sails-hook-uploads)_:NA
DB adapter & version _(e.g. [email protected])_: Custom Oracle
Skipper adapter & version _(e.g. [email protected])_: NA


When setting limit=-1 in the api call, sails returns the following:

Deprecated: In previous versions of Waterline, the specified limit (-1) would work the same as if you > had omitted the limit altogether-- i.e. defaulting to Number.MAX_SAFE_INTEGER. If that is what you > are intending to happen, then please just omit limit instead, which is a more explicit and future-proof > way of doing the same thing.
Warning: This backwards compatibility will be removed
in a future release of Sails/Waterline. If this usage
is left unchanged, then queries like this one will eventually
fail with an error.

The issue is that by default Sails limits the records to 30 if limit is not specified. The "defaultLimit" parameter in blueprint.js does not appear to work any longer. What are the current methods for returning all records for a blueprint route (single route only AND all blueprint routes)?

blueprints helpful info or workaround needs better error message needs documentation question

All 8 comments

@abatkins Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

  • look for a workaround. _(Even if it's just temporary, sharing your solution can save someone else a lot of time and effort.)_
  • tell us why this issue is important to you and your team. What are you trying to accomplish? _(Submissions with a little bit of human context tend to be easier to understand and faster to resolve.)_
  • make sure you've provided clear instructions on how to reproduce the bug from a clean install.
  • double-check that you've provided all of the requested version and dependency information. _(Some of this info might seem irrelevant at first, like which database adapter you're using, but we ask that you include it anyway. Oftentimes an issue is caused by a confluence of unexpected factors, and it can save everybody a ton of time to know all the details up front.)_
  • read the code of conduct.
  • if appropriate, ask your business to sponsor your issue. _(Open source is our passion, and our core maintainers volunteer many of their nights and weekends working on Sails. But you only get so many nights and weekends in life, and stuff gets done a lot faster when you can work on it during normal daylight hours.)_
  • let us know if you are using a 3rd party plugin; whether that's a database adapter, a non-standard view engine, or any other dependency maintained by someone other than our core team. _(Besides the name of the 3rd party package, it helps to include the exact version you're using. If you're unsure, check out this list of all the core packages we maintain.)_

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

Hey, @abatkins!

I've done a little bit of digging in our docs, and this section of the upgrade guide seems to indicate that limit: undefined might produce the behavior you're looking for.

If that doesn't work, we recommend creating a custom action.

Not specifying limit defaults to 30. I also tried limit=undefined in my api call. This returned a Bad Request. It does not seem that there is any non-deprecated way to change this default limit at this time. Furthermore, the error message that I listed above does not describe the actual behavior of blueprint routes. Omitting limit does not default to MAX_SAFE_INTEGER. It defaults to 30.

@abatkins Unlimited records is simply not available for Find in blueprint routes to prevent quickly overloading the client's RAM, however, if you're looking to move a lot of data at once, you could technically set blueprints to a very large number like 10,000, but that many records at once also risks of overloading ram.

We recommend writing a script to page through a stable amount of records at a time such as 1,000 for more powerful client systems. The same principle applies to other frameworks as well.

That's fine. But the deprecation message indicates it does. If this is not the case that message should be changed as well as the documentation. In addition it is not clear how you would override the default limit that is set to anything other than 30. The defaultLimit parameter in blueprints does not appear to work anymore.

@abatkins Thanks, these are definitely valid points and I'll have them discussed with the team for the best plan of action to update these three areas. In the meantime, have you checked out using limit with parseBlueprintOptions to override default behavior for blueprint actions?

Yes, but this looks like an override not a default. If I set queryoptions.criteria.limit it would override whatever limit value I set, not simply provide a default when the limit is not specified.

Hi, @abatkins. Yes, defaultLimit is no longer supported by the most recent version of Sails (per this bit of the upgrade guide); parseBlueprintActions allows one to configure blueprint behavior in its stead.

That said, it seems like a custom action might serve you best. See the docs for more information on actions.

Edit: In case you do decide to use parseBlueprintOptions, here's a link to where it's called in the source code.

Was this page helpful?
0 / 5 - 0 ratings