🐛 Bug Report: Execution.fromMap throws Bad state: No element when server doesn't return resourceType (pre-Sites servers

Aperta Adatta ai principianti
#1,858 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Aakriti7-giti ci sta già lavorando.

Dal 30/8/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
dart, flutter
Ambito
api

Direzione di ricerca

Inizia da lib/src/models/execution.dart e segui il modo in cui Functions.createExecution(), Functions.getExecution() e Functions.listExecutions() costruiscono Execution a partire dalle risposte legacy. Confronta i campi resourceType/resourceId con la precedente forma della risposta functionId; il lavoro è completato quando queste chiamate non generano più eccezioni e continuano a esporre lo stato dell’esecuzione, il corpo della risposta e gli altri dati restituiti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
👟 Reproduction steps

Since appwrite: 26.0.0, Execution.fromMap (in lib/src/models/execution.dart) parses the resourceType field like this:

resourceType: enums.ExecutionResourceType.values.firstWhere(
  (e) => e.value == map['resourceType'],
),

This throws Bad state: No element on any self-hosted Appwrite server that predates the Functions/Sites unification and therefore doesn't send a resourceType field in the execution response — it still returns the older shape with functionId instead of resourceId/resourceType.

Because firstWhere has no orElse, this crashes on every Functions.createExecution() / Functions.getExecution() / Functions.listExecutions() call against such a server, even though the HTTP call itself succeeds (2xx) and the function executes correctly — the data is simply lost because the SDK can't build the Execution model from a valid response.

To Reproduce

  1. Point the SDK at a self-hosted Appwrite server running a version prior to the Functions/Sites unification (i.e. one that still returns functionId on executions instead of resourceId + resourceType).
  2. Call Functions.createExecution(...).
  3. The function executes successfully server-side, but the SDK throws:
Bad state: No element
#0 ListBase.firstWhere (dart:collection/list.dart:132:5)
#1 new Execution.fromMap (package:appwrite/src/models/execution.dart:92:56)
#2 Functions.createExecution (package:appwrite/services/functions.dart:81:29)

Raw response for such an execution (obtained via the REST API directly) looks like:

{
"$id": "...",
"functionId": "test-function-id",
"trigger": "http",
"status": "completed",
"responseStatusCode": 200,
"responseBody": "...",
...
}

Note the absence of resourceId / resourceType.

👍 Expected behavior

The SDK shouldn't hard-crash when the server predates a schema change. At minimum, resourceType should fall back to a sane default (e.g. functions, inferred from the presence of the legacy functionId field) instead of throwing, so callers can still get responseBody/status/etc. Ideally the SDK would also surface a clear version-mismatch error rather than an opaque Bad state: No element.

👎 Actual Behavior

It throw an error

🎲 Appwrite version

Appwrite Cloud

💻 Operating system

Linux

🧱 Your Environment
  • appwrite (Dart/Flutter SDK): 26.0.0
  • Platform: Flutter, iOS/Android
  • Server: self-hosted Appwrite (pre-Sites-unification version)
👀 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?
Lingua principale
Twig
Stelle
330
Fork
212
Merge medio
12h 3m
PR unite (30g)
131

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di appwrite/sdk-generator

Tutte le issue di appwrite/sdk-generator

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.