Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDatastore.manager issue in sails-mongo@2.1.0 #7314

Closed
makeitcount opened this issue Dec 12, 2023 · 9 comments
Closed

getDatastore.manager issue in sails-mongo@2.1.0 #7314

makeitcount opened this issue Dec 12, 2023 · 9 comments

Comments

@makeitcount
Copy link

Node version: 16.20.0
Sails version (sails): 1.5.8
ORM hook version (sails-hook-orm): 4.0.2
Sockets hook version (sails-hook-sockets): 2.0.4
Grunt hook version (sails-hook-grunt): 5.0.0
DB adapter & version (e.g. sails-mongo): 2.1.0


After recent upgrade of sails-mongo, following query stated failing without any warning/error and never returns the control back to the callback.

This works on sails-mongo@2.0.0 (and node v14) but not not on sails-mongo@2.1.0 (and node v16)

MyModel.getDatastore().manager.collection(MyModel.tableName).aggregate(pipelineArray).toArray(function (errA, applications) { 
     //code never reaches here 
})
@sailsbot
Copy link

@makeitcount 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.

@makeitcount
Copy link
Author

makeitcount commented Dec 12, 2023

@DominusKelvin can you please review your PR for sails-mongo@2.1.0 once again? I just commented on the code which might have caused this issue (I believe so because I debugged that using breakpoint but I don't have any idea how to fix that)

@DominusKelvin
Copy link
Contributor

@DominusKelvin can you please review your PR for sails-mongo@2.1.0 once again? I just commented on the code which might have caused this issue (I believe so because I debugged that using breakpoint but I don't have any idea how to fix that)

Great catch. I'll have a look.

@DominusKelvin
Copy link
Contributor

@DominusKelvin can you please review your PR for sails-mongo@2.1.0 once again? I just commented on the code which might have caused this issue (I believe so because I debugged that using breakpoint but I don't have any idea how to fix that)

Can you try making it a promise because the underlying Mongo instance is no longer callback based but promise based. Also read the upgrade guide as it discusses the changes needed in userland code 👇🏾

https://blog.sailscasts.com/sails-mongo-v2-1-0

@makeitcount
Copy link
Author

https://blog.sailscasts.com/sails-mongo-v2-1-0

I do not fully understand the change suggested here. The other exec callbacks are working fine for me. What is this iife change suggested here? How should the above code I mentioned should look like?

@DominusKelvin
Copy link
Contributor

https://blog.sailscasts.com/sails-mongo-v2-1-0

I do not fully understand the change suggested here. The other exec callbacks are working fine for me. What is this iife change suggested here? How should the above code I mentioned should look like?

Well .exec is Sails/Waterline code. .toArray is not. It's the underlying adapter so it needs to be a promise so .toArray().then().catch()

The IIFE is meant to reduce the change you need but if converting to promise works for you then that's fine.

@makeitcount
Copy link
Author

Well .exec is Sails/Waterline code. .toArray is not. It's the underlying adapter so it needs to be a promise so .toArray().then().catch()

Ok. So if I replace .toArray() with .exec(function(err, results){}), that will also work, right?
If this is possible then it would be easier to keep things consistent across the codebase i.e. callback only.

@DominusKelvin
Copy link
Contributor

Well .exec is Sails/Waterline code. .toArray is not. It's the underlying adapter so it needs to be a promise so .toArray().then().catch()

Ok. So if I replace .toArray() with .exec(function(err, results){}), that will also work, right?

If this is possible then it would be easier to keep things consistent across the codebase i.e. callback only.

Yeah let me know if that works for you. General rule is if you are using the underlying MongoDB driver instance, you have to move to promises. If you have been using .exec on the other hand then no need to change anything. Let me know if that works for you then I can close this issue.

@DominusKelvin
Copy link
Contributor

Hey @makeitcount I'll be closing this issue as resolved since from our conversations you can resolve this in userland via a couple of suggested options. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants