Skip to content

fix: invalid date in object causes unhandled promise rejection in beforeSave trigger #7193

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

Open
wants to merge 43 commits into
base: alpha
Choose a base branch
from

Conversation

sunshineo
Copy link
Contributor

@sunshineo sunshineo commented Feb 15, 2021

New Pull Request Checklist

Issue Description

Related issue: #7192

Approach

TODOs before merging

  • Add test cases
  • Add entry to changelog
  • Add changes to documentation (guides, repository pages, in-code descriptions)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

@codecov
Copy link

codecov bot commented Feb 15, 2021

Codecov Report

Merging #7193 (e0bfdcb) into alpha (20fc4e2) will increase coverage by 0.31%.
The diff coverage is 100.00%.

❗ Current head e0bfdcb differs from pull request most recent head 4d9edb4. Consider uploading reports for the commit 4d9edb4 to get more accurate results

@@            Coverage Diff             @@
##            alpha    #7193      +/-   ##
==========================================
+ Coverage   93.82%   94.13%   +0.31%     
==========================================
  Files         182      182              
  Lines       13629    13635       +6     
==========================================
+ Hits        12787    12835      +48     
+ Misses        842      800      -42     
Impacted Files Coverage Δ
src/triggers.js 95.42% <100.00%> (+0.06%) ⬆️
src/RestWrite.js 94.30% <0.00%> (-0.16%) ⬇️
src/Adapters/Cache/RedisCacheAdapter.js 87.71% <0.00%> (+75.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8cf0b5e...4d9edb4. Read the comment docs.

@mtrezza
Copy link
Member

mtrezza commented Feb 15, 2021

Thanks for this PR. Can you please add a test case that covers the issue this PR intends to fix?

@sunshineo
Copy link
Contributor Author

I don't know how to add a test case that setup beforeSave on a class with Date. Can someone provide some pointers?

@mtrezza
Copy link
Member

mtrezza commented Feb 16, 2021

Please look into the .spec.js files, there are test cases for saving an object as well as the beforeSave trigger. Combining both should yield the test case needed.

This would also be the code example that I asked for in the related issue.

@sunshineo
Copy link
Contributor Author

I still have no time to learn the test system. So I spent half an hour to setup a project to demo the bug
https://github.com/sunshineo/parse-bug-demo
I hope the README.md is enough, but I can answer any questions

@mtrezza
Copy link
Member

mtrezza commented Feb 23, 2021

Can you merge the latest commit of master?

@mtrezza
Copy link
Member

mtrezza commented Feb 23, 2021

From your comment:

I do not see any strong reason that we have to have 111 instead of 142. So I'll change the expected error message in the test and put it on my PR.

The error codes are not arbitrary, we have to pick the right one. As I commented in my PR, there may be an additional issue that we are getting two different error codes and messages for the same error.

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also add a CHANGELOG entry?

@sunshineo sunshineo force-pushed the validation-beforesave branch from bb27d24 to 69d92f0 Compare March 10, 2021 18:56
@sunshineo
Copy link
Contributor Author

@mtrezza Changelog added

@sunshineo
Copy link
Contributor Author

Hello @mtrezza . I think I addressed everything. Let's merge it

@sunshineo
Copy link
Contributor Author

@mtrezza Have a look now

@sunshineo
Copy link
Contributor Author

Hello, can some one merge this? @mtrezza @ @dplewis @davimacedo

@mtrezza
Copy link
Member

mtrezza commented Mar 30, 2021

@sunshineo Can you please merge the current master into it to make the tests pass?

@sunshineo
Copy link
Contributor Author

I just merged master into this branch.

@sunshineo
Copy link
Contributor Author

@mtrezza @dplewis It's been a while, let's merge this. The change properly return error and fix the bug that hangs the whole server. The error code and message can be improved in the future if user feedback suggest it is confusing

mtrezza and others added 19 commits March 27, 2022 22:44
# [5.3.0-alpha.4](parse-community/parse-server@5.3.0-alpha.3...5.3.0-alpha.4) (2022-04-04)

### Bug Fixes

* custom database options are not passed to MongoDB GridFS ([parse-community#7911](parse-community#7911)) ([a72b384](parse-community@a72b384))
# [5.3.0-alpha.6](parse-community/parse-server@5.3.0-alpha.5...5.3.0-alpha.6) (2022-04-11)

### Bug Fixes

* peer dependency mismatch for GraphQL dependencies ([parse-community#7934](parse-community#7934)) ([b7a1d76](parse-community@b7a1d76))
# [5.3.0-alpha.7](parse-community/parse-server@5.3.0-alpha.6...5.3.0-alpha.7) (2022-04-25)

### Bug Fixes

* security upgrade @parse/fs-files-adapter from 1.2.1 to 1.2.2 ([parse-community#7948](parse-community#7948)) ([20fc4e2](parse-community@20fc4e2))
@zanderisrael
Copy link

I still seeing this in 5.0, whats going on looks like a simple fix...
Is there a workaround I can do for now?

@mtrezza mtrezza requested a review from a team April 27, 2022 11:40
@mtrezza
Copy link
Member

mtrezza commented Apr 27, 2022

It seems the changes just need to be reviewed then we can release this as an alpha version.

try {
response['object'] = request.object._getSaveJSON();
} catch (error) {
// https://github.com/parse-community/parse-server/issues/7192
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pleas remove the comment, it's not necessary

try {
parseObjectJSON = parseObject.toJSON();
} catch (error2) {
// https://github.com/parse-community/parse-server/issues/7192
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove comment; I think also error2 is unused, so you could remove it as well?

@mtrezza mtrezza changed the title fix validation error with beforeSave trigger fix: invalid date in object causes unhandled promise rejection in beforeSaveTrigger Apr 27, 2022
@parse-github-assistant
Copy link

parse-github-assistant bot commented Apr 27, 2022

Thanks for opening this pull request!

  • 🎉 We are excited about your hands-on contribution!

@mtrezza mtrezza changed the title fix: invalid date in object causes unhandled promise rejection in beforeSaveTrigger fix: invalid date in object causes unhandled promise rejection in beforeSave trigger Apr 27, 2022
{ __type: 'Date', iso: 'invalidIsoDate' },
{ __type: 'Date', iso: '' },
];
for (const date of dates) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer

await Promise.all(dates.map(async date  => {
  ...
}));

@mtrezza mtrezza force-pushed the alpha branch 2 times, most recently from 59215e6 to e6d7d8f Compare May 1, 2022 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants