Fix SQLite crash: don't ORDER BY DateTimeOffset
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:
co-authored by
Claude Opus 4.8
parent
e323a2e882
commit
2ce89fa490
@@ -102,7 +102,7 @@ else
|
||||
await using var db = await DbFactory.CreateDbContextAsync();
|
||||
pending = await db.Invites
|
||||
.Where(i => i.AcceptedAt == null)
|
||||
.OrderByDescending(i => i.CreatedAt)
|
||||
.OrderByDescending(i => i.Id) // Id grows with creation; SQLite can't ORDER BY DateTimeOffset
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ else
|
||||
owned = await db.Wishlists
|
||||
.Include(w => w.Items)
|
||||
.Where(w => w.OwnerId == userId)
|
||||
.OrderByDescending(w => w.CreatedAt)
|
||||
.OrderByDescending(w => w.Id) // Id grows with creation; SQLite can't ORDER BY DateTimeOffset
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class WishlistService(IDbContextFactory<ApplicationDbContext> dbFactory)
|
||||
await using var db = await dbFactory.CreateDbContextAsync();
|
||||
return await db.Wishlists
|
||||
.Where(w => w.OwnerId == userId)
|
||||
.OrderByDescending(w => w.CreatedAt)
|
||||
.OrderByDescending(w => w.Id) // Id grows with creation; SQLite can't ORDER BY DateTimeOffset
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -144,5 +144,17 @@ public class WishlistServiceTests : IDisposable
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user