appwrite / appwrite/sdk-generator

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

Open Beginner friendly
#1,858 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Twig
Stars
325
Forks
212
Avg merge
7h 36m
Merged PRs (30d)
91

Description

### 👟 Reproduction steps

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

```dart
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?

- [x] I checked and didn't find similar issue

### 🏢 Have you read the Code of Conduct?

- [x] I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)

Contributor guide

Open the contributing guide

Research direction

Start in lib/src/models/execution.dart and trace how Functions.createExecution(), Functions.getExecution(), and Functions.listExecutions() construct Execution from legacy responses. Compare the resourceType/resourceId fields with the older functionId response shape; done means these calls no longer throw and still expose the execution status, response body, and other returned data.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.