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: Error when updating ParseObject with relation to another object #805

Closed
wants to merge 10 commits into from

Conversation

juriSacchetta
Copy link
Contributor

@juriSacchetta juriSacchetta commented Dec 9, 2022

New Pull Request Checklist

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

Issue Description

Closes: #696

If you try to add a relationship to an object and after you do another operation to it you'll face this error:

Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'ParseRelation?' in type cast

By adding a relation, the set method of ParseObject changes the value corresponding to the key. Thus, the next time the relation is attempted, there will be no instance of ParseRelation but a Map.

final PostModel = ...;
final LikeModel like = LikeModel();

like.onPost = post;
await like.save();

post.likeRelation.add(like); // or post.addRelation('likes', [post]);
ParseResponse resp = await post.update();
if (resp.success) {
  post.likeRelation.remove(like); // Bad
}

Approach

To solve this bug, I had to insert an if within the set method, but it is not a clean solution. I could not find a better solution. Honestly, I think using the same map to store both data and operations is a risky decision.

The last change concerns the creation of a relation in the client.
Every time the relation was accessed, a new one was created, thus also losing the cache function that was already implemented.
I tried to always return the same instance.

TODOs before merging

  • Add tests
  • Add changes to documentation (guides, repository pages, in-code descriptions)
  • A changelog entry

@parse-github-assistant
Copy link

parse-github-assistant bot commented Dec 9, 2022

Thanks for opening this pull request!

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

@mtrezza
Copy link
Member

mtrezza commented Dec 9, 2022

Could you please create an issue, move the explanation to that issue and just reference the issue in this PR?

I just noticed you changed some links in the template, I will correct that.

@codecov
Copy link

codecov bot commented Dec 9, 2022

Codecov Report

Patch coverage: 57.89% and project coverage change: -4.61 ⚠️

Comparison is base (d7339cd) 26.71% compared to head (7843787) 22.11%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #805      +/-   ##
==========================================
- Coverage   26.71%   22.11%   -4.61%     
==========================================
  Files          47       47              
  Lines        2905     2908       +3     
==========================================
- Hits          776      643     -133     
- Misses       2129     2265     +136     
Impacted Files Coverage Δ
packages/dart/lib/src/utils/parse_decoder.dart 73.58% <ø> (ø)
packages/dart/lib/src/objects/parse_relation.dart 47.61% <11.11%> (-6.55%) ⬇️
packages/dart/lib/src/objects/parse_object.dart 48.76% <100.00%> (-41.92%) ⬇️

... and 4 files with indirect coverage changes

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 in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@juriSacchetta
Copy link
Contributor Author

I was testing my code, it introduces other problems. Please, do not merge this version.

I'll send another version of it. I'm already working on it!

@juriSacchetta
Copy link
Contributor Author

It should work now 😁

Let me know!!

@mtrezza mtrezza changed the title Fix issue #696, bug in the update handling for relations in ParseObject fix: error when updating ParseObject with relation to another object Dec 10, 2022
@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title fix: error when updating ParseObject with relation to another object fix: Error when updating ParseObject with relation to another object Dec 10, 2022
mbfakourii
mbfakourii previously approved these changes Dec 10, 2022
Copy link
Member

@mbfakourii mbfakourii left a comment

Choose a reason for hiding this comment

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

The code has been tested, it seems good.
@juriSacchetta is it possible to add the test?

@juriSacchetta
Copy link
Contributor Author

At the moment, I didn't write a test but I've tested it inside my project. It seems to work fine.

Maybe in the next few days, I'll write one. I can't guarantee it, my schedule is very busy sorry.

@mtrezza
Copy link
Member

mtrezza commented Dec 12, 2022

Thanks for your feedback, we'll keep this open until a test is added.

@juriSacchetta
Copy link
Contributor Author

Hey guys I added a new test relation specific. Let me know if it can be enough :)

@mtrezza
Copy link
Member

mtrezza commented Feb 22, 2023

Rebased and started CI

Copy link
Member

@mbfakourii mbfakourii left a comment

Choose a reason for hiding this comment

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

Tests are not like other tests, please write like other samples
Please write based on this file

Copy link
Member

@mbfakourii mbfakourii left a comment

Choose a reason for hiding this comment

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

The rest of the parts are fine, just move the duplicate codes to the setup section

packages/dart/test/relation_test.dart Show resolved Hide resolved
packages/dart/test/relation_test.dart Outdated Show resolved Hide resolved
@xanderelsmith
Copy link

Hi , please i keep getting this issue "Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'ParseRelation?' in type cast"

how dp i fix it?

@mtrezza
Copy link
Member

mtrezza commented Feb 26, 2023

@xanderelsmith is this related to this PR?

@mbfakourii
Copy link
Member

Hi , please i keep getting this issue "Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'ParseRelation?' in type cast"

how dp i fix it?

This issue is not related to this section. Please open an issue if you have a problem

@juriSacchetta
Copy link
Contributor Author

Hey there!
I noticed that my branch has been merged, so can I close the PR? Thanks again :)

Copy link
Member

@mbfakourii mbfakourii left a comment

Choose a reason for hiding this comment

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

It was tested and there is no problem

@mbfakourii
Copy link
Member

Hey there! I noticed that my branch has been merged, so can I close the PR? Thanks again :)

No, it has not been merged yet

@xanderelsmith
Copy link

@xanderelsmith is this related to this PR?

Yes

@mtrezza
Copy link
Member

mtrezza commented Feb 27, 2023

@xanderelsmith How is it related to this PR? Could you give more details?

@xanderelsmith
Copy link

It throws an error, when removing a parse object from a parse relation

@xanderelsmith
Copy link

You said something about the data becoming a map once
newobject.remove() is done

@xanderelsmith
Copy link

New Pull Request Checklist

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

Issue Description

Closes: #696

If you try to add a relationship to an object and after you do another operation to it you'll face this error:

Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'ParseRelation?' in type cast

By adding a relation, the set method of ParseObject changes the value corresponding to the key. Thus, the next time the relation is attempted, there will be no instance of ParseRelation but a Map.

final PostModel = ...;
final LikeModel like = LikeModel();

like.onPost = post;
await like.save();

post.likeRelation.add(like); // or post.addRelation('likes', [post]);
ParseResponse resp = await post.update();
if (resp.success) {
  post.likeRelation.remove(like); // Bad
}

Approach

To solve this bug, I had to insert an if within the set method, but it is not a clean solution. I could not find a better solution. Honestly, I think using the same map to store both data and operations is a risky decision.

The last change concerns the creation of a relation in the client. Every time the relation was accessed, a new one was created, thus also losing the cache function that was already implemented. I tried to always return the same instance.

TODOs before merging

  • Add tests
  • Add changes to documentation (guides, repository pages, in-code descriptions)
  • A changelog entry

This🤲

@juriSacchetta
Copy link
Contributor Author

Hey guys, I tested this code version and it seems to work fine for me. @xanderelsmith can you give me more details?

Copy link
Member

@Nidal-Bakir Nidal-Bakir 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 your contribution @juriSacchetta, I'm working to fix this issue and other issues related to using Maps to store the operations, I'm using a more OOP approach to improve and fix all of them using ParseOperations, and the ParseMergeTool class will be removed. I will definitely take a look at your code and see if I use any of it. Thanks again for your work.

Here is my PR: #860

@parse-community/flutter-sdk-review, I'd like to request that we don't merge this pull request just yet. Can we hold off for a bit? I'm working on a more comprehensive solution.

Thanks

@mtrezza
Copy link
Member

mtrezza commented Mar 25, 2023

Fine with me, @mbfakourii what do you think?

Do you have an ETA for the other PR you're working on? If it takes longer, another possibility may be to merge this for a quick fix and mere the comprehensive fix later on.

@Nidal-Bakir
Copy link
Member

Nidal-Bakir commented Mar 25, 2023

I'm currently working on the ParseRelation and it is the last thing to do on my list of TODOs, then I will add tests and documentation for the functions and classes and then I will do any refactoring/cleaning when I look at it again.

I think I need a week or less.

another possibility may be to merge this for a quick fix and merge the comprehensive fix later on.

Sure, that sounds good. Give me some time to review and test this PR.

@Nidal-Bakir
Copy link
Member

Nidal-Bakir commented Mar 25, 2023

This is a breaking change! I'm sorry, but it's not a quick fix anymore.
We need to be careful with it and open a discussion about it.

@Nidal-Bakir Nidal-Bakir added the state:breaking Breaking change requires major version increment and `BREAKING CHANGE` commit message label Mar 25, 2023
@Nidal-Bakir
Copy link
Member

Can you update your master branch to be in sync with upstream, so you can see the added tests? I just checked out your master and pulled the test files from upstream, and the tests are reporting syntax errors and failing.

@mbfakourii
Copy link
Member

Fine with me, @mbfakourii what do you think?

Do you have an ETA for the other PR you're working on? If it takes longer, another possibility may be to merge this for a quick fix and mere the comprehensive fix later on.

I think it is good and there is no problem

@juriSacchetta
Copy link
Contributor Author

Fine with me, @mbfakourii what do you think?

Do you have an ETA for the other PR you're working on? If it takes longer, another possibility may be to merge this for a quick fix and mere the comprehensive fix later on.

Hi guys, I really need this fix as soon as possible. This solution would be perfect for me.
Please resolve fast this problem in any way you prefer.

Thank you for your work 😁

@Nidal-Bakir
Copy link
Member

Nidal-Bakir commented Mar 29, 2023

Hi guys, I really need this fix as soon as possible. This solution would be perfect for me.
Please resolve fast this problem in any way you prefer.

We are working on it!

You can just use the SDK as an embedded package in your project and import it using its path: ./ in the pubspec.yaml
when you have the SDK embedded in your project you can just do and fix it as you wish.

here is a code snippte:

  parse_server_sdk_flutter:
    path: ./Parse-SDK-Flutter/packages/flutter

see (https://docs.flutter.dev/development/packages-and-plugins/using-packages#dependencies-on-unpublished-packages)

@Nidal-Bakir
Copy link
Member

Completed via #860

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:breaking Breaking change requires major version increment and `BREAKING CHANGE` commit message
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ParseRelation#query - Unhandled Exception: type 'ParseObject' is not a subtype of type *
5 participants