Repository navigation
Conversation
…umns The change detector formatted the new value of a date column with the local calendar day, while every driver writes a utc: true column with the UTC day. West of UTC, a UTC-midnight Date one day after the stored value formatted as the stored day, so save() sent no UPDATE. Fixes typeorm#12945
Code Review by Qodo
1.
|
The previous commit formatted only the new value of a utc: true date
column in UTC. The stored value still used the local day, so a column
whose transformer returns a Date compared 2025-06-01 against 2025-05-31
in New York and save() sent an UPDATE for an unchanged entity. Both
sides now use { utc: column.utc }.
The new test loads such a row, saves it unchanged and checks that the
version column stays at 1. It passes on master, fails on the previous
commit and passes here. Found by the Qodo review on this PR.
commit: |
Cprakhar
approved these changes
Oct 11, 2026
alumni
approved these changes
Oct 11, 2026
2 of 4 tasks
hktitof
added a commit
to hktitof/typeorm
that referenced
this pull request
Nov 25, 2026
A date array reached the driver as Date objects, because mixedDateToDateString() hands an array back unchanged, so pg serialized each element in the process time zone and the column kept the local calendar day. With utc: true a day west of UTC was stored one day early, and saving the entity again wrote the same wrong day back. Format the elements of an array column the way the scalar path already does, in both drivers that support array columns. This is the array arm of typeorm#12949, which fixed the changed-column comparison.
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.
Description of change
Fixes #12945
With
@Column({ type: "date", utc: true }),save()drops an edit to the column when the process runs west of UTC. UnderTZ=America/New_York, load a row holding2025-05-31, set the column tonew Date(Date.UTC(2025, 5, 1))andsave(): no UPDATE goes out and the row keeps2025-05-31.update()with the same Date writes2025-06-01.SubjectChangedColumnsComputerformats the new value withDateUtils.mixedDateToDateString(normalizedValue)and noutc, so in New York 2025-06-01T00:00Z comes out as2025-05-31, equals the stored value, and the column is skipped:typeorm/packages/typeorm/src/persistence/SubjectChangedColumnsComputer.ts
Lines 110 to 122 in 5d5fc38
#11740 added the option and passes
{ utc: columnMetadata.utc }on every driver's write and hydrate path. Change detection was the one place it missed, so now both sides of that comparison, the new value and the stored one, get{ utc: column.utc }.utc: falsecolumns format the same as before. I leftdate[]alone, since its write path ignoresutcas well.Probe on master vs this branch, better-sqlite3 and postgres 17, New York (UTC and Tokyo were already fine):
The test extends
date-utc.test.ts, which already runs in New York. It movesutcDateto the next UTC day andlocalDateto 22:00 the day before (local), saves, and reads both back. ThelocalDatehalf catches a fix that formats everything in UTC. On master it fails on better-sqlite3, sqljs and postgres withexpected '2025-05-31' to equal '2025-06-01', and passes with the fix.Pull-Request Checklist
masterbranchFixes #NNNN,Closes #NNNN, orResolves #NNNNtests/**.test.ts)docs/docs/**.md): N/A