Skip to content

fix(storage): preserve sortBy defaults when list receives a partial sortBy - #1490

Merged
spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-1089-paritystorage-preserve-sortby-defaults-when-list-receives
Jun 29, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-1089-paritystorage-preserve-sortby-defaults-when-list-receives

Conversation

@spydon

@spydon spydon commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What

storage.from(bucket).list() rejected a partially-specified SortBy with a 400.

SortBy's constructor had no default for column/order, so SortBy(column: 'updated_at') left order as null. Since SearchOptions.toMap() always emits both keys and the storage client serializes with json.encode (which keeps nulls), the request body sent:

"sortBy": { "column": "updated_at", "order": null }

The Storage server requires both column and order, so it returned a 400.

This mirrors supabase-js #2454 (commit 42b7bbc), which deep-merges the partial sortBy onto the defaults.

Fix

Give SortBy constructor defaults so any partially-specified SortBy fills in the missing field, which is the idiomatic Dart equivalent of the JS deep-merge and works wherever SortBy is constructed:

const SortBy({this.column = 'name', this.order = 'asc'});

Behavior:

  • SortBy(column: 'updated_at') → {column: 'updated_at', order: 'asc'}
  • SortBy(order: 'desc') → {column: 'name', order: 'desc'}
  • list() with no options → {column: 'name', order: 'asc'} (unchanged)

No breaking change for callers passing a complete SortBy.

Tests

Added a list sortBy defaults group in client_test.dart (using the in-memory CustomHttpClient to inspect the request body) covering partial column, partial order, no options, and complete sortBy.

Closes SDK-1089

…ortBy

A partial SortBy (e.g. SortBy(column: 'updated_at')) left the unset field
null, so list() sent sortBy: {column: 'updated_at', order: null}. The Storage
server requires both column and order, returning a 400.

Give SortBy constructor defaults so a partially-specified SortBy fills in the
missing field from the defaults.
@spydon
spydon requested a review from a team as a code owner June 29, 2026 08:30
@github-actions github-actions Bot added the storage This issue or pull request is related to storage label Jun 29, 2026
Handle SortBy fields passed explicitly as null (Dart defaults only apply to
omitted arguments) by falling back to the defaults in toMap(), and collapse the
duplicated SearchOptions default to const SortBy().
@spydon
spydon merged commit c68a964 into main Jun 29, 2026
27 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-1089-paritystorage-preserve-sortby-defaults-when-list-receives branch June 29, 2026 17:23
spydon added a commit that referenced this pull request Aug 21, 2026
…1752)

## What

`StorageFileApi.list()` took its sort direction as a `String`:

```dart
SortBy(column: 'created_at', order: 'desc')
```

Nothing validated that string, so `order: 'ascending'` or `order:
'DESC'` compiled fine and only
surfaced as a 400 from the storage server.

While fixing that, the same asc/desc direction turned out to be modelled
three times over:

| Enum | Package | Used by |
| --- | --- | --- |
| `BucketSortOrder` | `supabase_storage` |
`ListBucketsOptions.sortOrder` |
| `FileSortOrder` | `supabase_storage` | `FileSort.order`
(`listPaginated`) |
| `SortDirection` | `iceberg` | `SortField.direction` |

All three had identical `ascending('asc')` / `descending('desc')`
values.

## Change

One `SortDirection` in `supabase_common`, re-exported from `iceberg` and
`supabase_storage` (and so
from `supabase` and `supabase_flutter`):

```dart
enum SortDirection {
  ascending('asc'),
  descending('desc');

  const SortDirection(this.value);

  /// The value sent to and received from the API.
  final String value;

  static SortDirection fromValue(String value) =>
      values.firstWhere((direction) => direction.value == value);
}
```

`SortBy.order` is now that enum, non-nullable and defaulting to
`SortDirection.ascending`:

```dart
const SortBy({
  this.column = 'name',
  this.order = SortDirection.ascending,
});
```

`column` stays a `String?` with its `'name'` default, since `list()`
accepts any column of a
`FileObject` while `FileSortColumn` only covers the three the paginated
endpoint sorts by.
supabase-swift made the same `SortBy` change in its storage v3 rewrite
(supabase/supabase-swift#987).

`SortDirection` is the name that survives rather than `SortOrder`,
because `package:iceberg`
already has a public `SortOrder` class (the Iceberg spec's sort-order
object, with `orderId` and
`fields`) that `supabase_storage` re-exports, so a `SortOrder` enum
would make the name ambiguous
for consumers.

The wire format is untouched: every serializer still emits `asc` /
`desc`.

## Breaking changes

- `BucketSortOrder` and `FileSortOrder` are gone; use `SortDirection`,
whose values are identical
- `SortBy(order: 'desc')` becomes `SortBy(order:
SortDirection.descending)`
- `SortBy(order: null)` no longer compiles; leave `order` out to sort
ascending

`iceberg` callers are unaffected: `SortDirection` keeps its name and is
still exported from
`package:iceberg/iceberg.dart`.

Documented in `MIGRATION.md`. The default-filling behavior from #1490 is
preserved: a partial
`SortBy` still sends both keys, and `order` can no longer be null at
all.

## Query ordering keeps its bool

`PostgrestTransformBuilder.order()` and `SupabaseStreamBuilder.order()`
deliberately keep
`ascending: bool` rather than taking a `SortDirection`. They build the
`asc` / `desc` string
internally, so there was never an invalid value a caller could pass, and
the bool matches
supabase-js (`{ ascending: false }`) and supabase-swift, which keeps
shared docs and cross-SDK
examples portable. v3 already changed that call once by flipping the
`ascending` default, so an
enum would make users touch the same line twice for no safety gain.

## Compliance matrix

`BucketSortOrder` and `FileSortOrder` are removed from the storage
features. `SortDirection` was
already registered in the shared `supporting_symbols` block for iceberg,
which is the right home
for it now that no single capability owns it. `.sdk-parse-ignore` gains
an exception for
`sort_direction.dart`, alongside the existing one for
`retry_options.dart`, since both are
`supabase_common` sources the clients re-export as user facing API.

## Tests

- `SortBy.toMap` covers the null column fallback and the enum
serialization
- The `list sortBy defaults` group passes the enum, and its
explicit-null case narrowed to `column`
  since `order` cannot be null anymore

`dart test` passes for `supabase_storage` (203), `iceberg` (30) and
`supabase_common` (109), and
`dart analyze` is clean across `packages` and `examples`.

Closes #1491
Closes SDK-1549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage This issue or pull request is related to storage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants