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

_TypeError on addRelation #999

Open
engeen opened this issue Jun 5, 2024 · 3 comments
Open

_TypeError on addRelation #999

engeen opened this issue Jun 5, 2024 · 3 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@engeen
Copy link

engeen commented Jun 5, 2024

New Issue Checklist

Issue Description

Having:

Order Class

class Order extends ParseObject implements ParseCloneable {
  Order() : super(_keyTableName);
  Order.clone() : this();

  @override
  clone(Map map) => Order.clone()..fromJson(Map<String, dynamic>.from(map));

  static const String _keyTableName = 'Order';
  static const String keyInitialProduct = 'initial_product';
  static const String keyProduct = 'product';
  static const String keyPrice = 'price';
  static const String keyCertainDate = 'certain_date';
  static const String keyState = 'state';
  static const String keyAccount = 'account';


  Product? get initialProduct => get(keyInitialProduct);
  set initialProduct(Product? initialProduct) =>
      set(keyInitialProduct, initialProduct);

  Product? get product => get(keyProduct);
  set product(Product? product) => set(keyProduct, product);

  Account? get account => get(keyAccount);
  set account(Account? account) => set(keyAccount, account);

  DateTime? get certainDate => get<DateTime?>(keyCertainDate);
  set certainDate(DateTime? certainDate) =>
      set<DateTime?>(keyCertainDate, certainDate);

}

Order Schema

{
  "className": "Order",
  "fields": {
    "objectId": {
      "type": "String"
    },
    "createdAt": {
      "type": "Date"
    },
    "updatedAt": {
      "type": "Date"
    },
    "ACL": {
      "type": "ACL"
    },
    "initial_product": {
      "type": "Pointer",
      "targetClass": "Product",
      "required": false
    },
    "receivers": {
      "type": "Relation",
      "targetClass": "Contact",
      "required": false
    },
    "price": {
      "type": "Number",
      "required": false
    },
    "certain_date": {
      "type": "Date",
      "required": false
    },
    "state": {
      "type": "String",
      "required": true,
      "defaultValue": "draft"
    },
    "account": {
      "type": "Pointer",
      "targetClass": "Account",
      "required": true
    },
    "product": {
      "type": "Pointer",
      "targetClass": "Product",
      "required": false
    }
  },
  "classLevelPermissions": {
    "find": {
      "*": true
    },
    "count": {
      "*": true
    },
    "get": {
      "*": true
    },
    "create": {
      "*": true
    },
    "update": {
      "*": true
    },
    "delete": {
      "*": true
    },
    "addField": {
      "*": true
    },
    "protectedFields": {
      "*": []
    }
  },
  "indexes": {
    "_id_": {
      "_id": 1
    }
  }
}

Contact class

class Contact extends ParseObject implements ParseCloneable {
  Contact() : super(_keyTableName);
  Contact.clone() : this();

  /// Mimic a clone due to Flutter not using reflection
  @override
  clone(Map map) => Contact.clone()..fromJson(Map<String, dynamic>.from(map));

  static const String _keyTableName = 'Contact';
  static const String keyName = 'name';
  static const String keyPhone = 'phone';
  static const String keyAddress = 'address';
  static const String keyBirthday = 'birthday';
  static const String keyAccount = 'account';

  String? get name => get<String?>(keyName);
  set name(String? name) => set<String?>(keyName, name);

  String? get phone => get<String?>(keyPhone);
  set phone(String? phone) => set<String?>(keyPhone, phone);

  String? get address => get<String?>(keyAddress);
  set address(String? address) => set<String?>(keyAddress, address);

  DateTime? get birthday => get<DateTime?>(keyBirthday);
  set birthday(DateTime? birthday) => set<DateTime?>(keyBirthday, birthday);

  Account? get account => get<Account?>(keyAccount);
  set account(Account? account) => set<Account?>(keyAccount, account);

}

Steps to reproduce

      List<Contact> contactsObjects = (result as Set)
          .map((key) => Contact()..objectId = key.value)
          .toList();

      var order = widget.order!;
      order.addRelation('receivers', contactsObjects);

Actual Outcome

Screenshot 2024-06-05 at 19 34 45

_TypeError (type '_Set' is not a subtype of type 'Set' in type cast)

_ParseRelation.preformRelationOperation (/Users/yuriy/.pub-cache/hosted/pub.dev/parse_server_sdk-6.4.0/lib/src/objects/parse_relation.dart:96)
_ParseOperation._handelRelationOperation (/Users/yuriy/.pub-cache/hosted/pub.dev/parse_server_sdk-6.4.0/lib/src/objects/parse_operation/parse_operation.dart:159)
_ParseOperation._handelOperation (/Users/yuriy/.pub-cache/hosted/pub.dev/parse_server_sdk-6.4.0/lib/src/objects/parse_operation/parse_operation.dart:111)
_ParseOperation.maybeMergeWithPrevious (/Users/yuriy/.pub-cache/hosted/pub.dev/parse_server_sdk-6.4.0/lib/src/objects/parse_operation/parse_operation.dart:90)
ParseBase.set (/Users/yuriy/.pub-cache/hosted/pub.dev/parse_server_sdk-6.4.0/lib/src/objects/parse_base.dart:250)
ParseObject.addRelation (/Users/yuriy/.pub-cache/hosted/pub.dev/parse_server_sdk-6.4.0/lib/src/objects/parse_object.dart:571)
_SelectReceiversState._selectContacts (/Users/yuriy/dev/gf/gfapp/lib/widgets/order_select_receivers.dart:83)
(Unknown Source:0)

Expected Outcome

Adding relation

Environment

Parse Flutter SDK

  • SDK version: 8.0
  • Flutter version: 3.19.6
  • Dart version: 3.3.4
  • Operating system version: MacOS Sonoma 14.4.1

Server

  • Parse Server version: 4.5.0

Logs

Debug console:
_ParseRelation.preformRelationOperation (package:parse_server_sdk/src/objects/parse_relation.dart:96:58)

Copy link

parse-github-assistant bot commented Jun 5, 2024

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.

@mbfakourii
Copy link
Member

Did you register the model classes with registeredSubClassMap?

@mbfakourii mbfakourii added the type:bug Impaired feature or lacking behavior that is likely assumed label Jun 5, 2024
@engeen
Copy link
Author

engeen commented Jun 5, 2024

@mbfakourii , yes, sure.

But, here is an update. The problem is gone if create new one Order instance:

      List<Contact> contactsObjects = (result as Set)
          .map((key) => Contact()..objectId = key.value)
          .toList();

      var order = Order()..set('objectId', widget.order!.objectId);
      order.addRelation('receivers', contactsObjects);

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
Development

No branches or pull requests

2 participants