[12.x] Adjust freshTimestamp for SQL Server#58614
Conversation
|
Feels like this could be breaking. |
|
@taylorotwell Could you please explain why "it feels breaking"? |
|
@aimeos He means you should essentially target the master branch (13.x), as it feels risky for 12.x :) So, probably worth opening a new branch targeting 13.x |
|
Let's merge it and find out then. :) |
|
@taylorotwell Should I create a PR for 11.x too? |
|
This is breaking our CI. If If anything, there needs to be a callback that can be registered, such as what @AndrewMast proposed |
|
There are tests now failing for me too, due to this change. For now I have worked around it by adding the old version of
Agreed. |
|
I would potentially send a revert PR to 12.x for now as seems a B/C and then a solution can be done in a separate PR. |
…laravel#58614)" This reverts commit 7fa1c8f.
|
@calebdw Default timestamps have a precision of 0 by default in Eloquent models. If you've changed the default timestamp format in the model to use microseconds, you should overwrite freshTimestamp() to return @taylorotwell As it does break more as I thought, reverting the PR in 12.x is OK but I would like to get that into 13.x nevertheless to streamline default behavior across all supported databases. |
|
@aimeos, I would prefer @AndrewMast solution to make it easy to override for all models, not just models that extend a particular base class |
|
Should this not be controlled by I am overriding this to Wouldn't it make sense to use this when dealing with I see When I said "default" previously, I meant the default for your setup, which would be Edit: Maybe |
Contrary to other RDBMS, SQL Server stores microseconds in timestamps regardless of the timestamp precision and rounds the timestamp according to the microsecond value. This often leads to "off by one second" timestamps esp. in tests because timestamps stored as "2026-02-04 11:39:54.742" are rounded to "2026-02-04 11:39:55" while the original timestamp in Laravel is still "2026-02-04 11:39:54".
This fix ensures that all timestamps are stored with "000" as microseconds to ensure compatibility with all other RDBMS and to avoid the "off by one" problem in tests. The fix isn't breaking and if microseconds for timestamps are required, they can still be enabled in the booted() method of the model.