appwrite / sdk-for-flutter

[READ-ONLY] Official Appwrite Flutter SDK 💙
https://appwrite.io
BSD 3-Clause "New" or "Revised" License
369 stars 111 forks source link

🐛 Bug Report: Missing null check in Document.fromMap factory #175

Closed joern-h closed 3 months ago

joern-h commented 1 year ago

👟 Reproduction steps

Databases listDocuments with select query that does not include $permissions field

👍 Expected behavior

Document object should be constructed with an empty $permissions list

Proposed change:

  factory Document.fromMap(Map<String, dynamic> map) {
    return Document(
      $id: map['\$id'].toString(),
      $collectionId: map['\$collectionId'].toString(),
      $databaseId: map['\$databaseId'].toString(),
      $createdAt: map['\$createdAt'].toString(),
      $updatedAt: map['\$updatedAt'].toString(),
      $permissions: map['\$permissions'] ?? [], // add null check
      data: map,
    );
  }

👎 Actual Behavior

factory Document.fromMap throws exception: 'Null' is not a subtype of type 'List'

  factory Document.fromMap(Map<String, dynamic> map) {
    return Document(
      $id: map['\$id'].toString(),
      $collectionId: map['\$collectionId'].toString(),
      $databaseId: map['\$databaseId'].toString(),
      $createdAt: map['\$createdAt'].toString(),
      $updatedAt: map['\$updatedAt'].toString(),
      $permissions: map['\$permissions'], // null exception 
      data: map,
    );
  }

🎲 Appwrite version

Different version (specify in environment)

💻 Operating system

Linux

🧱 Your Environment

Appwrite 1.4.2 Flutter SDK: 11.0.0

👀 Have you spent some time to check if this issue has been raised before?

🏢 Have you read the Code of Conduct?

joern-h commented 1 year ago

This is related to https://github.com/appwrite/appwrite/issues/6158

stnguyen90 commented 3 months ago

Closing as duplicate of https://github.com/appwrite/appwrite/issues/6158