Fix SQLite crash: don't ORDER BY DateTimeOffset
Build & Push Docker image / test (push) Successful in 47s
Build & Push Docker image / docker (push) Successful in 1m19s

SQLite can't translate ORDER BY on DateTimeOffset columns, so loading the
wishlists/invites pages threw NotSupportedException. Order by the autoincrement
Id (same newest-first result) instead. Add a regression test that exercises the
owned/shared list queries against SQLite.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
Jim Basso
2026-06-11 15:36:28 -05:00
co-authored by Claude Opus 4.8
parent e323a2e882
commit 2ce89fa490
4 changed files with 15 additions and 3 deletions
@@ -102,7 +102,7 @@ else
await using var db = await DbFactory.CreateDbContextAsync(); await using var db = await DbFactory.CreateDbContextAsync();
pending = await db.Invites pending = await db.Invites
.Where(i => i.AcceptedAt == null) .Where(i => i.AcceptedAt == null)
.OrderByDescending(i => i.CreatedAt) .OrderByDescending(i => i.Id) // Id grows with creation; SQLite can't ORDER BY DateTimeOffset
.ToListAsync(); .ToListAsync();
} }
@@ -79,7 +79,7 @@ else
owned = await db.Wishlists owned = await db.Wishlists
.Include(w => w.Items) .Include(w => w.Items)
.Where(w => w.OwnerId == userId) .Where(w => w.OwnerId == userId)
.OrderByDescending(w => w.CreatedAt) .OrderByDescending(w => w.Id) // Id grows with creation; SQLite can't ORDER BY DateTimeOffset
.ToListAsync(); .ToListAsync();
} }
+1 -1
View File
@@ -21,7 +21,7 @@ public class WishlistService(IDbContextFactory<ApplicationDbContext> dbFactory)
await using var db = await dbFactory.CreateDbContextAsync(); await using var db = await dbFactory.CreateDbContextAsync();
return await db.Wishlists return await db.Wishlists
.Where(w => w.OwnerId == userId) .Where(w => w.OwnerId == userId)
.OrderByDescending(w => w.CreatedAt) .OrderByDescending(w => w.Id) // Id grows with creation; SQLite can't ORDER BY DateTimeOffset
.ToListAsync(); .ToListAsync();
} }
@@ -144,5 +144,17 @@ public class WishlistServiceTests : IDisposable
Assert.NotNull(await _svc.GetDetailAsync(1, OwnerId)); // owner always Assert.NotNull(await _svc.GetDetailAsync(1, OwnerId)); // owner always
} }
[Fact]
public async Task Owned_and_shared_list_queries_run_on_sqlite()
{
// Regression: these order by a timestamp; SQLite can't ORDER BY DateTimeOffset, so the
// service must order by a supported column. This would throw NotSupportedException otherwise.
var owned = await _svc.GetOwnedAsync(OwnerId);
Assert.Single(owned);
var shared = await _svc.GetSharedWithAsync(FriendId);
Assert.Single(shared); // the AllMembers list is visible to other members
}
public void Dispose() => _db.Dispose(); public void Dispose() => _db.Dispose();
} }