Fix DateTime fields returning Invalid Date with unixepoch-ms#29274
Fix DateTime fields returning Invalid Date with unixepoch-ms#29274jacek-prisma merged 4 commits intoprisma:mainfrom
Conversation
WalkthroughBigint handling in the better-sqlite3 adapter was changed to convert safe bigints to numbers and keep unsafe bigints as strings. Added functional tests validating DateTime fields stored as unix-epoch milliseconds are returned as valid Date objects across create/retrieve, aggregate, and INTEGER-column scenarios. Changes
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
packages/adapter-better-sqlite3/src/conversion.tspackages/client/tests/functional/unixepoch-ms-datetime/tests.ts
packages/client/tests/functional/unixepoch-ms-datetime/tests.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Fixes DateTime fields becoming Invalid Date when using the BetterSQLite3 driver adapter with timestampFormat: "unixepoch-ms" by adjusting how BigInt query results are mapped back into JSON-compatible values, and adds regression coverage for unix-millis stored directly in SQLite.
Changes:
- Update BetterSQLite3 result mapping to convert
bigintvalues tonumberwhen they fit safely, falling back tostringotherwise. - Add functional tests to assert valid
Dateobjects are returned when unix-millis timestamps are stored directly (including aggregates).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/client/tests/functional/unixepoch-ms-datetime/tests.ts | Adds regression tests for reading DateTime values when unix-millis are stored directly and when aggregating. |
| packages/adapter-better-sqlite3/src/conversion.ts | Adjusts row value conversion so safe bigint values are returned as number (helps unixepoch-ms DateTime parsing). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/client/tests/functional/unixepoch-ms-datetime/tests.ts
Outdated
Show resolved
Hide resolved
packages/client/tests/functional/unixepoch-ms-datetime/tests.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
This doesn't actually address #28890, because that issue is only reproducible by creating the date column manually with type set to |
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/client/tests/functional/unixepoch-ms-datetime/tests.ts (1)
111-130:⚠️ Potential issue | 🟡 MinorTest intent mismatch:
findUnique()in name butfindFirst()in codeLine 111 says
findUnique(), but Line 122 executesfindFirst(). Also,found?.createdAt+found!mixes null-safe and non-null assertions in the same test. Please align the name/query and assert non-null once before dereference.Suggested fix
- test('findUnique() returns valid Date when createdAt is stored as unix millis directly', async () => { + test('findFirst() returns valid Date when createdAt is stored as unix millis directly', async () => { const prisma = createClient(info, driverAdapter) const uuid = randomUUID() const nowMillis = Date.now() await prisma.$executeRaw` INSERT INTO Event (name, uuid, createdAt) VALUES ('event', ${uuid}, ${nowMillis}) ` const found = await prisma.event.findFirst({ where: { uuid, }, }) - expect(found?.createdAt).toBeInstanceOf(Date) + expect(found).not.toBeNull() + expect(found!.createdAt).toBeInstanceOf(Date) expect(isNaN(found!.createdAt.getTime())).toBe(false) })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 555faf9f-b116-4801-8ff3-cdf5818f8b96
📒 Files selected for processing (1)
packages/client/tests/functional/unixepoch-ms-datetime/tests.ts
|
Thanks for flagging this. I added a test that creates a DateTime column backed by INTEGER and stores unixepoch-ms values to reproduce the issue discussed in #28890. The test now verifies that Prisma Client returns a valid Date (not Invalid Date) for that DateTime column. |
Summary
Fix DateTime fields returning
Invalid Datewhen usingunixepoch-ms.Changes
unixepoch-ms(millisecond timestamps).unixepoch-ms.Tests
Fixes #28890
Summary by CodeRabbit
Bug Fixes
Tests