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] Columns of type "Object" merging with old value on Postgres #4815

Merged
merged 1 commit into from
Jun 7, 2018

Conversation

jaeggerr
Copy link
Contributor

@jaeggerr jaeggerr commented Jun 7, 2018

After this discussion #4808

The PR fixes an issue with Postgres due to this commit #2984.

When updating a field of type object (JSON object), the previous and new values are merged.
This is not the expected behaviour as it is not documented and not happening in MongoDB.

@codecov
Copy link

codecov bot commented Jun 7, 2018

Codecov Report

Merging #4815 into master will decrease coverage by 0.13%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4815      +/-   ##
==========================================
- Coverage   92.82%   92.68%   -0.14%     
==========================================
  Files         119      119              
  Lines        8684     8684              
==========================================
- Hits         8061     8049      -12     
- Misses        623      635      +12
Impacted Files Coverage Δ
...dapters/Storage/Postgres/PostgresStorageAdapter.js 97.15% <100%> (-0.36%) ⬇️
src/Adapters/Auth/meetup.js 84.21% <0%> (-5.27%) ⬇️
src/Adapters/Auth/linkedin.js 81.81% <0%> (-4.55%) ⬇️
src/Adapters/Auth/facebook.js 80% <0%> (-4%) ⬇️
src/Routers/PushRouter.js 92.85% <0%> (-3.58%) ⬇️
src/Adapters/Auth/facebookaccountkit.js 72.72% <0%> (-3.04%) ⬇️
src/Controllers/SchemaController.js 96.48% <0%> (-0.24%) ⬇️
src/Controllers/DatabaseController.js 94.64% <0%> (-0.2%) ⬇️
src/RestWrite.js 93.61% <0%> (-0.19%) ⬇️

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 1afc34e...e67edd1. Read the comment docs.

Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

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

LGTM! Tests pass which is amazing!

@@ -1980,4 +1980,31 @@ describe('Parse.Object testing', () => {
done();
})
});

it ('Update object field should store exactly same sent object', async (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using async/await, there’s no need for done as a param and call at the end of the method

@flovilmart flovilmart merged commit cf3a872 into parse-community:master Jun 7, 2018
@dplewis
Copy link
Member

dplewis commented Jun 7, 2018

@flovilmart I think more test are needed for this. See as getting rid of COALESE doesn’t change anything here.

The use of ‘unset’ is a workaround.

Also {} merged with { c: “d” } is the same as {} updated to { c: “d” }

@flovilmart
Copy link
Contributor

@dplewis, are you able to write a failing test? The unset, because not saved after I believe has no effect?

@dplewis
Copy link
Member

dplewis commented Jun 7, 2018

@flovilmart Here is the failing test per #4808 (comment)

The unset here looks weird to me. Also COALESE is just to prevent null values don't see how that fixes this.

@flovilmart
Copy link
Contributor

Uhm ok. Not a PG expert. I assumed the test was failing before te fix :)

@jaeggerr
Copy link
Contributor Author

jaeggerr commented Jun 7, 2018

I am not a PG expert neither but I did not just remove the COALESE but I replaced
( COALESCE($${index}:name, '{}'::jsonb) by {}'::jsonb

As far as I understand, it will take the previously stored value or {} if it is null.
Then, there is a || that merges the left part with the right part.
The purpose of the PR is to remove $${index}:name to prevent the old value to be merged with the new one.

@dplewis
Copy link
Member

dplewis commented Jun 7, 2018

@jaeggerr Just ran a few more tests looks right. So {} gets set then you add and remove from it right?

flovilmart pushed a commit that referenced this pull request Aug 12, 2018
flovilmart pushed a commit that referenced this pull request Aug 12, 2018
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
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