Fix record changed() logic for comparing current value Dates #695
+337
−4
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.
We are currently not calculating
record.changed
correctly for datetime fields as we compare the current value as a Date instance against the previous value which is stored as a string. We need to make sure that in any case where the current/previous is being compared as a Date vs string we convert the string to a Date and compare the actual dates based on that.@pistachiobaby if you can pls 🎩 :) :
To see the problem:
Product
modelupdate
action in therun
function, add (before theawait save(record)
call)Add the same snippet in the
onSuccess
functionproduct/update
webhook to create the product record with the create action. Trigger the webhook again to actually run the update actionrecord.changed("publishedAt")
condition was false in therun
function and no log in it is shownrecord.changed("publishedAt")
condition was true in theonSuccess
function and the log in it is shown even though thepublishedAt
didn't actually change! <--- this is the bugTo see the fix:
/packages/api-client-core
pnpm build
and thenpnpm pack
to generate the tarballdev
if its currently running the main gadget repopackage.json
set the @gadgetinc/api-client-core package to point to the newly generated tarballDo the same in
UserlandDependencyVersions.ts
9. Run
pnpm install
10. run
dev
again11. Follow the same steps as before but this time see that
record.changed("publishedAt")
is correctly false in theonSuccess
functionPR Checklist