Repository navigation
fix(storage): preserve sortBy defaults when list receives a partial sortBy - #1490
Merged
spydon merged 2 commits intoJun 29, 2026
Conversation
…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.
grdsdev
approved these changes
Jun 29, 2026
spydon
commented
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
storage.from(bucket).list()rejected a partially-specifiedSortBywith a 400.SortBy's constructor had no default forcolumn/order, soSortBy(column: 'updated_at')leftorderasnull. SinceSearchOptions.toMap()always emits both keys and the storage client serializes withjson.encode(which keeps nulls), the request body sent:The Storage server requires both
columnandorder, so it returned a 400.This mirrors supabase-js #2454 (commit
42b7bbc), which deep-merges the partialsortByonto the defaults.Fix
Give
SortByconstructor defaults so any partially-specifiedSortByfills in the missing field, which is the idiomatic Dart equivalent of the JS deep-merge and works whereverSortByis constructed: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 defaultsgroup inclient_test.dart(using the in-memoryCustomHttpClientto inspect the request body) covering partial column, partial order, no options, and complete sortBy.Closes SDK-1089