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

fix: server crashes on MongoDB GeoJSON error instead of throwing Parse.Error #7347

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

Conversation

mstniy
Copy link
Contributor

@mstniy mstniy commented Apr 14, 2021

New Pull Request Checklist

  • [ x] I am not disclosing a vulnerability.
  • [ x] I am creating this PR in reference to an issue.

Issue Description

Creating an object in a collection with a spatially indexed field fails if that field of the new object does not contain valid geometry. This is not handled by Parse, causing an INTERNAL_SERVER_ERROR that makes it difficult to diagnose invalid geojsons.

Related issue: #7331

Approach

Geojson errors produced by Mongo are cought and turned into Parse errors.

TODOs before merging

  • [ x ] Add test cases
  • Add entry to changelog
  • Add changes to documentation (guides, repository pages, in-code descriptions)
  • Add security check
  • [ x ] Add new Parse Error codes to Parse JS SDK
  • Depend on a release of the js sdk, instead of a commit hash.

@ghost
Copy link

ghost commented Apr 14, 2021

Warnings
⚠️ Please add a changelog entry for your changes.

Generated by 🚫 dangerJS

@codecov
Copy link

codecov bot commented Apr 14, 2021

Codecov Report

Merging #7347 (ec1f80d) into alpha (8a126fc) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

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

Impacted file tree graph

@@            Coverage Diff             @@
##            alpha    #7347      +/-   ##
==========================================
- Coverage   94.20%   94.19%   -0.01%     
==========================================
  Files         182      182              
  Lines       13587    13590       +3     
==========================================
+ Hits        12799    12801       +2     
- Misses        788      789       +1     
Impacted Files Coverage Δ
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 93.41% <100.00%> (+0.25%) ⬆️
src/RestWrite.js 93.88% <0.00%> (-0.32%) ⬇️

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 8a126fc...0301472. Read the comment docs.

Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Let's wait for the new version of the SDK and we are good to merge this one.

package.json Outdated Show resolved Hide resolved
testSchema.addIndex('geospatial_index', {
geometry: '2dsphere',
});
await testSchema.save();
Copy link
Member

Choose a reason for hiding this comment

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

I want to make sure we don't introduce a flaky test here. This awaits the schema save, but not the index building in DB.

Maybe you want to look into schema tests to see what do we usually use in these cases, a timeout?

cc @dplewis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test is not flaky for me. The collection starts empty, so index building should take close to no time.
I couldn't find any tests for addIndex on the server codebase. The JS sdk has several, but none of them seem to explicitly wait on index-building.

Copy link
Member

Choose a reason for hiding this comment

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

I think there is no way to verify index building via Parse, so the only way would be connecting directly to mongodb and checking the status. Or modify Parse adapter to include that. I believe this test will not be flaky but a timeout (maybe 1 or 2s) could be helpful as well.

Copy link
Member

Choose a reason for hiding this comment

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

Ok then let's merge it as it is and see how it goes. I will run the tests a few times here to see whether its flaky already.

Modified an existing test to work with the new sdk release
  ParseUser.get('password') used to return undefined, now password is not an attribute
@mstniy
Copy link
Contributor Author

mstniy commented Aug 17, 2021

@davimacedo The PR now uses the latest SDK release, which includes the INVALID_VALUE error code

@mtrezza
Copy link
Member

mtrezza commented Sep 3, 2021

⚠️ Important change for merging PRs from Parse Server 5.0 onwards!

We are planning to release the first beta version of Parse Server 5.0 in October 2021.

If a PR contains a breaking change and is not merged before the beta release of Parse Server 5.0, it cannot be merged until the end of 2022. Instead it has to follow the Deprecation Policy and phase-in breaking changes to be merged during the course of 2022.

One of the most voiced community feedbacks was the demand for predictability in breaking changes to make it easy to upgrade Parse Server. We have made a first step towards this by introducing the Deprecation Policy in February 2021 that assists to phase-in breaking changes, giving developers time to adapt. We will follow-up with the introduction of Release Automation and a branch model that will allow breaking changes only with a new major release, scheduled for the beginning of each calendar year.

We understand that some PRs are a long time in the making and we very much appreciate your contribution. We want to make it easy for PRs that contain a breaking change and were created before the introduction of the Deprecation Policy. These PRs can be merged with a breaking change without being phased-in before the beta release of Parse Server 5.0. We are making this exception because we appreciate that this is a time of transition that requires additional effort from contributors to adapt. We encourage everyone to prepare their PRs until the end of September and account for review time and possible adaptions.

If a PR contains a breaking change and should be merged before the beta release, please mention @parse-community/server-maintenance and we will coordinate with you to merge the PR.

Thanks for your contribution and support during this transition to Parse Server release automation!

@mtrezza
Copy link
Member

mtrezza commented Feb 12, 2022

@mstniy Do you think we could get this ready for merge?

@mstniy mstniy marked this pull request as draft March 8, 2022 08:14
@mstniy mstniy marked this pull request as ready for review March 8, 2022 08:58
@mstniy mstniy requested a review from davimacedo March 8, 2022 09:03
testSchema.addIndex('geospatial_index', {
geometry: '2dsphere',
});
await testSchema.save();
Copy link
Member

Choose a reason for hiding this comment

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

I think there is no way to verify index building via Parse, so the only way would be connecting directly to mongodb and checking the status. Or modify Parse adapter to include that. I believe this test will not be flaky but a timeout (maybe 1 or 2s) could be helpful as well.

@mtrezza mtrezza changed the title Forward Mongo geojson errors as Parse.Error.INVALID_VALUE fix: server crashes on MongoDB GeoJSON errors instead of throwing Parse.Error Mar 31, 2022
@parse-github-assistant
Copy link

parse-github-assistant bot commented Mar 31, 2022

Thanks for opening this pull request!

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

@mtrezza mtrezza changed the title fix: server crashes on MongoDB GeoJSON errors instead of throwing Parse.Error fix: server crashes on MongoDB GeoJSON error instead of throwing Parse.Error Mar 31, 2022
@mtrezza
Copy link
Member

mtrezza commented Mar 31, 2022

@mstniy Could you rebase this on the alpha brach and resolve any conflicts?

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.

3 participants