Validate cursor value types - #669
Conversation
Yes, I think this function can go to |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #669 +/- ##
==========================================
+ Coverage 84.45% 86.58% +2.12%
==========================================
Files 15 15
Lines 1036 1021 -15
==========================================
+ Hits 875 884 +9
+ Misses 161 137 -24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Could you bump postgrex to make |
postgrex is bumped to 0.22.3 and hex.audit passes now. One thing worth mentioning: the lock diff is larger than just I first tried limiting the change to a single line in the lock file, but Mix rejects it. If you would prefer to keep this PR focused, I am happy to move the resync into a separate PR. |
|
All good, thank you very much! |
Description
Closes #668
This is the follow-up to the issue above. Since cursor validation only compared the cursor keys with the
order_byfields, a cursor with the right keys but a value of the wrong type would pass validation and only fail later with anEcto.Query.CastErrorwhen the query ran.Cursor values now go through
Ecto.Type.cast/2against the type of theirorder_byfield, reusing the same idea as the filter value casting. If a value can't be cast, validation returns an"is invalid"error on:after/:before— and withreplace_invalid_params: truethe cursor is simply dropped, as you suggested in the issue.I was careful not to change behavior where there's nothing to cast: without the
for:option, for fields that don't have a knownecto_type(join fields without the option, for example), and fornilvalues coming from nullable order fields, everything works as before.Two things I'd like your opinion on: I duplicated the small
expand_type/1helper that already exists (privately) inFlop.Filterto keep the diff small — happy to extract it somewhere shared instead. And the{:ecto_enum, _}clause isn't directly covered by tests, because no test schema has a sortable join field with that type; I can add one if you think it's worth it.Checklist