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

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

Closed
4 tasks done
kutear opened this issue Dec 14, 2021 · 5 comments
Closed
4 tasks done
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@kutear
Copy link

kutear commented Dec 14, 2021

New Issue Checklist

Issue Description

When i get a ParseRelation(relation) from a subClass of ParseObject, then build a QueryBuilder(queryBuilder) by relation.getQuery(), and invoke builder.query<Wallet>() to get a response. at this time i get some error.

E/flutter ( 7948): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'ParseObject' is not a subtype of type 'Wallet'
E/flutter ( 7948): #0      _ParseResponseBuilder._handleSuccess (package:parse_server_sdk/src/objects/response/parse_response_builder.dart:93:59)
E/flutter ( 7948): #1      _ParseResponseBuilder.handleResponse (package:parse_server_sdk/src/objects/response/parse_response_builder.dart:29:14)
E/flutter ( 7948): #2      handleResponse (package:parse_server_sdk/src/objects/response/parse_response_utils.dart:8:31)
E/flutter ( 7948): #3      ParseObject.query (package:parse_server_sdk/src/objects/parse_object.dart:419:14)

Steps to reproduce

    class Plan extends ParseObject {
    ...
    }

    final plan = ...;
    ParseRelation<Wallet> relation = plan.getRelation("wallets");
    QueryBuilder builder = relation.getQuery();
    final response = await builder.query<Wallet>();
    if (response.success) {
      // do something
    }



Actual Outcome

Unhandled Exception: type 'ParseObject' is not a subtype of type 'Wallet'

Expected Outcome

query success and get a list of Wallet

Environment

  parse_server_sdk_flutter: 3.1.0

Parse Flutter SDK

  • SDK version: 3.1.0
  • Operating system version: android

Server

  • Parse Server version: 3.1.0

Logs

None

@parse-github-assistant
Copy link

parse-github-assistant bot commented Dec 14, 2021

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza mtrezza added type:bug Impaired feature or lacking behavior that is likely assumed severity:medium labels Dec 15, 2021
@kutear
Copy link
Author

kutear commented Dec 16, 2021

other BUG

    final plan = ...;
    ParseRelation<Wallet> relation = plan.getRelation("wallets"); // This will be ok
    relation.add(someWallet); // or plan.addRelation("wallets", [someWallets]); 
    ParseRelation<Wallet> relation = plan.getRelation("wallets"); // Bad  
 Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'ParseRelation<ParseObject>?' in type cast

ParseObject#addRelation will modify the type of value _objectData['wallets'].

@kutear
Copy link
Author

kutear commented Dec 16, 2021

other BUG

    final plan = ...;
    ParseRelation<Wallet> relation = plan.getRelation("wallets"); // This will be ok
    relation.add(someWallet); // or plan.addRelation("wallets", [someWallets]); 
    ParseRelation<Wallet> relation = plan.getRelation("wallets"); // Bad  
 Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'ParseRelation<ParseObject>?' in type cast

ParseObject#addRelation will modify the type of value _objectData['wallets'].

Is my usage wrong? The ParseObject's _objectData is terrible, sometime it's include key - value, sometime it's include key - operation command.

/// Sets type [T] from objectData
///
/// To set an int, call setType<int> and an int will be saved
/// [bool] forceUpdate is always true, if unsure as to whether an item is
/// needed or not, set to false
void set<T>(String key, T value, {bool forceUpdate = true}) {
if (_getObjectData().containsKey(key)) {
if (_getObjectData()[key] == value && !forceUpdate) {
return;
}
_getObjectData()[key] =
ParseMergeTool().mergeWithPrevious(_unsavedChanges[key], value);
} else {
_getObjectData()[key] = value;
}
_unsavedChanges[key] = _getObjectData()[key];
}

Is it necessary to save data to _getObjectData()['key']?
And it's probably to save data to _unsavedChanges['key']? just like this,

  void set<T>(String key, T value, {bool forceUpdate = true}) {
    // if (_getObjectData().containsKey(key)) {
    //   if (_getObjectData()[key] == value && !forceUpdate) {
    //     return;
    //   }
    //   _getObjectData()[key] =
    //       ParseMergeTool().mergeWithPrevious(_unsavedChanges[key], value);
    // } else {
    //   _getObjectData()[key] = value;
    // }
    _unsavedChanges[key] = ParseMergeTool().mergeWithPrevious(_unsavedChanges[key], value);
  }

@RodrigoSMarques RodrigoSMarques mentioned this issue May 2, 2022
5 tasks
@mtrezza mtrezza linked a pull request May 30, 2022 that will close this issue
5 tasks
RodrigoSMarques added a commit to RodrigoSMarques/Parse-SDK-Flutter that referenced this issue Jun 2, 2022
### Bug Fixes
* Old version of connectivity_plus package ([parse-community#717](parse-community#717))
* package_info_plus not work in web ([parse-community#714](parse-community#714))
* MissingPluginException (No implementation found for method getAll) ([parse-community#712](parse-community#712))
* Query fails for subclassed Parse object in Parse relation ([parse-community#697](parse-community#697))
* ParseRelation#query - Unhandled Exception: type 'ParseObject' is not a subtype of type ([parse-community#696](parse-community#696))
* Error in progressCallback ([parse-community#679](parse-community#679))
* first: Correct return type ([parse-community#661](parse-community#661))
* ParseLiveListWidget MongoError ([parse-community#653](parse-community#653))

* General improvements
* Updated dependencies
* Fix Label Platform Web Support in pub.dev - Refactor path_provider access
@juriSacchetta
Copy link
Contributor

juriSacchetta commented Dec 8, 2022

Hey guys,
I got this error.
I spend two hours to be sure can it was not my fault, and after I found this issue.

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

I downloaded the repo and tried to see if the bug was been resolved, but unfortunately, it isn't.

I tried both the HEAD and #762 versions of the code, but nothing worked.

Can you help me?

Thanks a lot for your work!

    final plan = ...;
    ParseRelation<Wallet> relation = plan.getRelation("wallets"); // This will be ok
    relation.add(someWallet); // or plan.addRelation("wallets", [someWallets]); 
    ParseRelation<Wallet> relation = plan.getRelation("wallets"); // Bad  
 Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'ParseRelation<ParseObject>?' in type cast

@Nidal-Bakir
Copy link
Member

Fix via #860

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
4 participants