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: Saving a new Parse.Object with an unsaved Parse.File fails #1662

Merged
merged 14 commits into from
Feb 4, 2023

Conversation

swittk
Copy link
Contributor

@swittk swittk commented Jan 23, 2023

Fixes #1660 (Caused by passing a Parse.File into the LocalDataStore, which is unexpected)

New Pull Request Checklist

Issue Description

Saving a new Parse.Object with an unsaved Parse.File fails.

Closes: #1660

Approach

Checks that the object being pinned to the localDataStore is a ParseObject.

Fixes parse-community#1660 (Caused by passing a Parse.File into the LocalDataStore, which is unexpected)
@parse-github-assistant
Copy link

parse-github-assistant bot commented Jan 23, 2023

Thanks for opening this pull request!

  • ❌ Please edit your post and use the provided template when creating a new pull request. This helps everyone to understand your post better and asks for essential information to quicker review the pull request.

@swittk swittk changed the title Fixes pinning of objects that are not ParseObjects into LocalDataStore Fix : Saving Parse.Objects with unsaved Parse.File properties Jan 23, 2023
@swittk swittk changed the title Fix : Saving Parse.Objects with unsaved Parse.File properties fix: Saving Parse.Objects with unsaved Parse.File properties Jan 23, 2023
@mtrezza
Copy link
Member

mtrezza commented Jan 23, 2023

Could you add test ?

@codecov
Copy link

codecov bot commented Jan 23, 2023

Codecov Report

Base: 99.89% // Head: 99.89% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (d50b896) compared to base (1c96205).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #1662   +/-   ##
=======================================
  Coverage   99.89%   99.89%           
=======================================
  Files          61       61           
  Lines        5991     5992    +1     
  Branches     1373     1374    +1     
=======================================
+ Hits         5985     5986    +1     
  Misses          6        6           
Impacted Files Coverage Δ
src/ParseObject.js 99.89% <100.00%> (+<0.01%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@swittk
Copy link
Contributor Author

swittk commented Jan 23, 2023

I've added the test case

@mtrezza mtrezza requested a review from a team January 24, 2023 22:16
@dplewis
Copy link
Member

dplewis commented Jan 27, 2023

@swittk I wrote the entire LocalDatastore code myself. Can you add an integration test to replicate the issue? I might have overlooked this

@swittk
Copy link
Contributor Author

swittk commented Jan 28, 2023

It's not a bug related to the LocalDatastore itself I think; but rather in the save() method of ParseObject which allows both ParseObject | ParseFile

save(target: ParseObject | Array<ParseObject | ParseFile>, options: RequestOptions) {

But then in the then clause after saving all; it pins them all into the LocalDatastore, which, as far as I understand, expects only Parse.Objects, so when a Parse.File goes in it crashes.

for (const object of target) {

I've spent the past few hours trying to get it to fail in the integration test, but it won't. The situation does occur in-browser with Parse SDK 3.5.1 and 4.0.0 though (Parse.File reaching LocalDatastore causing the crash).

The test cases in ParseFile-test.js (not the integration ones) do fail due to the same _getId() calls, though, with Parse.Files getting passed into the save() method of ParseObject. So right now I'm not sure what the exact difference in code paths are between npm run test and npm run integration, and can't really demonstrate it; but the error really is there in-browser.

(Here's an example of what my current hotfix to the problem looks like in node_modules)
Screen Shot 2566-01-28 at 11 56 01

@dplewis
Copy link
Member

dplewis commented Jan 31, 2023

@swittk I can verify that this is an issue. Can you add this failing test to your PR and rebase?

it('can save file to localDatastore', async () => {
    Parse.enableLocalDatastore();
    const file = new Parse.File('parse-js-sdk', [61, 170, 236, 120]);
    const object = new Parse.Object('TestObject');
    await object.pin();

    object.set('file', file);
    await object.save();

    const query = new Parse.Query(TestObject);
    query.fromLocalDatastore();
    const results = await query.find();

    const url = results[0].get('file').url();
    assert.equal(results.length, 1);
    assert.notEqual(url, undefined);
    assert.equal(url, file.url());
  });

Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

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

Everything looks good so far

src/ParseObject.js Outdated Show resolved Hide resolved
Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

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

LGTM! Just waiting for the CI to pass

@swittk
Copy link
Contributor Author

swittk commented Feb 3, 2023

It seems like the CI hasn't run yet? ._.

@mtrezza
Copy link
Member

mtrezza commented Feb 3, 2023

Now it is running

@swittk
Copy link
Contributor Author

swittk commented Feb 4, 2023

I've tried running npm run integration on NodeJS 19.3.0 (same as the runner) and encountered the same issue.
It was solved by simply running npm install again after switching to node 19, and integration tests finished fine afterwards.
Screen Shot 2566-02-04 at 15 16 55

Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

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

LGTM! The flaky test will be fixed shortly.

@mtrezza mtrezza changed the title fix: Saving Parse.Objects with unsaved Parse.File properties fix: Saving a new Parse.Object with an unsaved Parse.File fails Feb 4, 2023
@mtrezza mtrezza merged commit 16535a4 into parse-community:alpha Feb 4, 2023
parseplatformorg pushed a commit that referenced this pull request Feb 4, 2023
# [4.0.0-alpha.9](4.0.0-alpha.8...4.0.0-alpha.9) (2023-02-04)

### Bug Fixes

* Saving a new `Parse.Object` with an unsaved `Parse.File` fails ([#1662](#1662)) ([16535a4](16535a4))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.0.0-alpha.9

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Feb 4, 2023
parseplatformorg pushed a commit that referenced this pull request Mar 1, 2023
# [4.1.0-beta.1](4.0.1...4.1.0-beta.1) (2023-03-01)

### Bug Fixes

* `LiveQuerySubscription.unsubscribe` resolves promise before unsubscribing completes ([#1727](#1727)) ([1c96205](1c96205))
* Node engine version upper range is <19 despite Node 19 support ([#1732](#1732)) ([febe187](febe187))
* Saving a new `Parse.Object` with an unsaved `Parse.File` fails ([#1662](#1662)) ([16535a4](16535a4))

### Features

* `LiveQueryClient.close` returns promise when WebSocket closes ([#1735](#1735)) ([979d660](979d660))
* Upgrade Node Package Manager lock file `package-lock.json` to version 2 ([#1729](#1729)) ([e993786](e993786))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.1.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Mar 1, 2023
parseplatformorg pushed a commit that referenced this pull request Mar 1, 2023
# [4.1.0-alpha.1](4.0.1...4.1.0-alpha.1) (2023-03-01)

### Bug Fixes

* `LiveQuerySubscription.unsubscribe` resolves promise before unsubscribing completes ([#1727](#1727)) ([1c96205](1c96205))
* Node engine version upper range is <19 despite Node 19 support ([#1732](#1732)) ([febe187](febe187))
* Saving a new `Parse.Object` with an unsaved `Parse.File` fails ([#1662](#1662)) ([16535a4](16535a4))

### Features

* `LiveQueryClient.close` returns promise when WebSocket closes ([#1735](#1735)) ([979d660](979d660))
* Upgrade Node Package Manager lock file `package-lock.json` to version 2 ([#1729](#1729)) ([e993786](e993786))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.1.0-alpha.1

parseplatformorg pushed a commit that referenced this pull request May 1, 2023
# [4.1.0](4.0.1...4.1.0) (2023-05-01)

### Bug Fixes

* `LiveQuerySubscription.unsubscribe` resolves promise before unsubscribing completes ([#1727](#1727)) ([1c96205](1c96205))
* Node engine version upper range is <19 despite Node 19 support ([#1732](#1732)) ([febe187](febe187))
* Saving a new `Parse.Object` with an unsaved `Parse.File` fails ([#1662](#1662)) ([16535a4](16535a4))

### Features

* `LiveQueryClient.close` returns promise when WebSocket closes ([#1735](#1735)) ([979d660](979d660))
* Upgrade Node Package Manager lock file `package-lock.json` to version 2 ([#1729](#1729)) ([e993786](e993786))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.1.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unsaved children does not work for unsaved Parse.File
4 participants