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

🐛 - User Object gives an error #33

Closed
dawid-niedzwiecki opened this issue Sep 25, 2021 · 9 comments
Closed

🐛 - User Object gives an error #33

dawid-niedzwiecki opened this issue Sep 25, 2021 · 9 comments
Assignees

Comments

@dawid-niedzwiecki
Copy link

Issue description:

when I execute User _response = await Connection.instance.account.get();, it gives an error:

E/flutter ( 6728): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'List<dynamic>' is not a subtype 
of type 'Map<String, dynamic>'
E/flutter ( 6728): #0      new User.fromMap (package:appwrite/src/models/user.dart:49:37)
E/flutter ( 6728): #1      Account.get (package:appwrite/services/account.dart:21:24)
E/flutter ( 6728): <asynchronous suspension>
E/flutter ( 6728): #2      UserModel.setUserData (package:expirapp/models/UserModel.dart:215:21) <- the mentioned line of code
E/flutter ( 6728): <asynchronous suspension>

I suppose the cause of this issue is that the resposne map in account.dart:19:

final res = await client.call(HttpMethod.get, path: path, params: params, headers: headers); 

is a map with a key "prefs" -> List:
image
Which later, in user.dart:41:

    return User(
      $id: map['\$id'],
      name: map['name'],
      registration: map['registration'],
      status: map['status'],
      passwordUpdate: map['passwordUpdate'],
      email: map['email'],
      emailVerification: map['emailVerification'],
      prefs: Preferences.fromMap(map['prefs']),
    );

gets treated as a map.

@lohanidamodar lohanidamodar self-assigned this Sep 26, 2021
@lohanidamodar
Copy link
Member

@dawid-niedzwiecki Can you please share the Appwrite Server version you are using?

@dawid-niedzwiecki
Copy link
Author

@dawid-niedzwiecki Can you please share the Appwrite Server version you are using?

It's 0.10.4:
Screenshot_2021-09-26-16-39-03-340_com android chrome

@dawid-niedzwiecki
Copy link
Author

Update

It came out, that it actually does work properly on newly created accounts. The issue happened on an account, that was created on a previous version of the Appwrite server. After deleting that account and creating a new one, the error didn't show up anymore.

@lohanidamodar
Copy link
Member

Update

It came out, that it actually does work properly on newly created accounts. The issue happened on an account, that was created on a previous version of the Appwrite server. After deleting that account and creating a new one, the error didn't show up anymore.

Could be a migration bug. We will take a look into it.

@stnguyen90
Copy link
Contributor

@dawid-niedzwiecki, was your account originally created via OAuth2?

@dawid-niedzwiecki
Copy link
Author

@dawid-niedzwiecki, was your account originally created via OAuth2?

Yes, via Google

@lohanidamodar
Copy link
Member

Closing this, as this should be fixed in the newer versions of SDK and Appwrite, if not feel free to reopen the issue.

@jonscoresby
Copy link

jonscoresby commented Nov 8, 2022

I'm new to Appwrite so hopefully this isn't out of place. I am using the latest versions of Appwrite server and SDK and I am getting this error. I have a realtime subscription to the account channel. The account channel returns a User object instead of an Account object. Not sure exactly why that is. Anyway, when I try to pass the response to the Account.fromMap() constructor and I get the error given in this issue. It seems that the prefs attribute in the User object returns a List instead of a Map. If I understand correctly, what used to be a User object is now an Account object and the Account response works correctly, but I am getting a User response where the prefs attribute is still the wrong type.

I'm not sure if this behavior is considered an error or not, but I'd thought I'd mention it. Perhaps I'm not using the application as intended.

@stnguyen90
Copy link
Contributor

@jonscoresby it might be best to either create a new issue or join us on Discord. If you want to create an issue, please make sure to include you code, full error, and the response from Appwrite. 🙏🏼

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

No branches or pull requests

5 participants