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
Dust doesn't render a result set obtained from MongoDB (by Mongoose) #487
Comments
Here is the same issue by the way: #479 I also confirm that But why it is not rendered without |
Is this mongo specific? Can you clarify what the dust issue is? |
@jimmyhchan it doesn't render the data. The data comes from MongoDB, I can see the data in |
Is it only a problem in 2.4. If so, one thing that did change was we stopped looking in the object prototype when determining the value of a reference. I'm guessing but does Mongo(oose) return a simple object or something wrapped up. That is, does the mongoose object have more methods then a simple Object/array. Another thing to check is the Your |
I have the same problem using a Mongoose object and Dust 2.4.0 (KrakenJS). |
It appears Mongoose returns a document (which looks like a plain JS object but is not). With Dust 2.4, we expect a real JS object. This might be what you need http://mongoosejs.com/docs/api.html#query_Query-lean. |
Likewise this appears to not work with Sequelize objects either. My templates look pretty bad as I have to access private members, like Coming from Jade, it is a bit awkward to have to jump through these hoops. I'm now adding a |
@jimmyhchan Mongoose objects are real JS objects. It is really bothersome to create dedicated "flat" data structures to please Dust inner works. The use of the prototypal chain to implement proxies or inheritance in nodeJS is really widespread, and do not make JS objects 'unreal' for that matter. |
I don't disagree. The mongoose object and the other prototype example is very useful. Dust 2.4 not support this is still a valid bug...but at least there is a work around. The original issue #469 is/was the bigger bug (IMO). I'm definitely open to providing support for this but need an implementation that also works for the general case. |
@jimmyhchan: I don't see how #469 relates in any way to the general case. It's not up to dusjts to handle badly chosen property names overriding method names in the prototype... I believe a helper to check ownProperty in dust helpers might fix the issue for the #469 use case. Why not revert what was done in #469 and go for a small helper for this very specific situation? Preventing prototypes from being read is actually preventing good JS to work. This looks bad to me. |
I believe that the general case should be to go through the prototypal chain, as dust always did, and let users be bitten if they name their "eventually empty properties" the same as "eventually existing methods" . |
So some options:
Any other options? I'm not oppose to going back to the pre 2.4 approach, my only argument is that it's likely easier and less surprising for devs to have to opt-in to prototypal chaining (it's more obviously borken) then for devs to have to opt-in to hasownproperty checks (more rare but subtlety borken). That said, supporting both modes feels wrong. |
Option 1 seems to be the most valid option from an end user's standpoint. It is unexpected that a valid Javascript object fails to work when assigned to a context. It took me quite a while to figure out why my conversion from Jade to Dust was failing so miserably (there is now an entire area of my project dedicated to simply marshaling ORM data for Dust templates). It wasn't until I stumbled across this issue that I even realized my Javascript object wasn't a Javascript object ("why does it say Paper Jam when there is no paper jam!?"). |
Chatting with a few others, seems the majority favor fixing this bug (allow prototype lookup) over the original bug. I'll try to get a pull request up to revert the previous change by next week for the next 2.4.X push. A quick pull request for anyone who has time. Thanks everyone for the lively discussion! |
Thank you very much for your feedback and action. On Wed, Aug 27, 2014 at 5:52 PM, jimmyhchan notifications@github.com
|
This has been reverted in 2.4.1. |
I'm unsure whether to create a new issue or simply comment on this one. Seeing as it contains some useful history on the issue, I'll post my comment here. I've just upgraded to version 2.7.1 and I've noticed that a Passportjs object retrieved from MongoDB causes my page to hang (no issues before the upgrade though). Wrapping it with the JSON.parse & JSON.stringify functions as follows does however seems to sort out the issue: res.render('casestudies', {
user : JSON.parse(JSON.stringify(req.user)),
assessments : req.assessments
}); What I find really strange is the same is not necessary for req.assessments with also happens to be retrieved from MongoDB.* *EDIT: This is incorrect. Seems I run into a similar problem with req.assessments too. This is what my User model looks like: var userSchema = mongoose.Schema({
local : {
name : String,
email : String,
password : String,
},
userRoles : [Number]
}); My apologies in advance if I'm doing something daft without realising it. |
Does either |
If so, can you share the versions of mongoose and mongodb you're using? |
I tried briefly to repro but I'm sure I'm only scratching the surface. It does seem that Dust is rendering the object returned by a
After running a couple times:
|
It looks like mongo Documents are Streamables, so my guess is that they aren't being |
dust.isThenable returns false
Mongoose: 3.8.28
I can confirm that we managed to reproduce the issue on another dev's machine as well. Please let me know if you need more info. Happy to help get this resolved although I can confirm that everything plays nicely when reverting back to dust 2.6.2 |
Thanks, I was able to reproduce it. So Documents in Mongo can be asynchronously delivered, but I don't think If you want to work around it for now, address Mongo Documents as So instead of:
Use:
Dust 2.7.0 added Streamable support which is why you don't see it before Thanks for the report! We'll get this behavior improved as soon as we can. On Thu, May 14, 2015 at 5:02 AM, vanmartin notifications@github.com wrote:
Seth Kinast |
Thanks! I managed to work out that it breaks on sections but not references by a process of elimination earlier in the week but honestly there's no immediate pressing need for me to upgrade my Dust version. Reverting back to 2.6.2 is my best option at the moment as I use sections in quite a number of my existing templates. I'll keep following the conversation on issue #663. |
I have an issue: Dust doesn't render a result set from MongoDB by Mongoose. But a custom made array of objects renders just fine. What is wrong? Why it happens? How to manage it? I use Windows 7 64bit if it matters.
Here is a code.
This is my controller. Pay attention to two
model
objects. The first one (custom made) isrendered fine. The second one (obtained from MongoDB) is not rendered.
A result set from MongoDB that is not rendered. Its Schema:
My
.dust
template code:The text was updated successfully, but these errors were encountered: