fix(dup): last_connection / last_disconnection timestamp unit#1134
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## release-1.2 #1134 +/- ##
===============================================
+ Coverage 63.21% 63.24% +0.03%
===============================================
Files 41 41
Lines 1968 1970 +2
===============================================
+ Hits 1244 1246 +2
Misses 724 724 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| defp pad_usec(datetime) do | ||
| # Ecto requires :utc_datetime_usec to be in microsecond precision | ||
| microsecond = | ||
| case datetime.microsecond do | ||
| {_, 0} -> {0, 6} | ||
| {n, _} -> {n, 6} | ||
| end | ||
|
|
||
| %{datetime | microsecond: microsecond} | ||
| end |
There was a problem hiding this comment.
Just Ecto.Type.cast!(:utc_datetime_usec, datetime) should work.
I think the only issue is where the code is preparing database changes with Ecto.Changeset.change which doesn't automatically cast params according to their Ecto types.
There was a problem hiding this comment.
If you don't like the case, I was experimenting and it looks like DateTime.add(datetime, 0, :microsecond) also sets the precision to 6
There was a problem hiding this comment.
I've changed it to DateTime.add(datetime, 0, :microsecond)
5403d94 to
8178378
Compare
8178378 to
b82c32d
Compare
timestamps were in millisecond precision, but `DateTime.from_unix!` was given microsecond precision. This caused datetimes to be incorrect. this was the result after setting up astarte in 5 minutes and running astarte-stream-qt5-test ``` ❯ docker compose exec -it scylla cqlsh -e 'select last_connection from test.devices;' last_connection --------------------------------- 1970-01-21 03:48:22.216000+0000 ``` Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
b82c32d to
042574f
Compare
As per astarte PR astarte-platform#1134 Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
a regression was introduced in 2c66918, where timestamps were in millisecond precision, but
DateTime.from_unix!was given microsecond precision. This caused datetimes to be incorrect.this was the result after setting up astarte in 5 minutes and running astarte-stream-qt5-test
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g. usage docs, diagrams, etc.: