appwrite / sdk-for-flutter

[READ-ONLY] Official Appwrite Flutter SDK πŸ’™

Home Page:https://appwrite.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Bug Report: Missing null check in Document.fromMap factory

joern-h opened this issue Β· comments

πŸ‘Ÿ 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?

  • I checked and didn't find similar issue

🏒 Have you read the Code of Conduct?

This is related to appwrite/appwrite#6158