-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a footgun in before-update
#196
Fix a footgun in before-update
#196
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #196 +/- ##
==========================================
- Coverage 83.60% 83.56% -0.04%
==========================================
Files 37 37
Lines 2501 2501
Branches 212 213 +1
==========================================
- Hits 2091 2090 -1
Misses 198 198
- Partials 212 213 +1 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
e273d39
to
2103be5
Compare
In a very precise condition, we would emit an `UPDATE` clause without any `WHERE` condition at all: - the `before-update` method's result does not have a primary key - the `where` clause in an `update!` call matches multiple rows - some part of the update map will change all matched rows - another part of the update map will change only a subset of matched rows If all these conditions are met, the bug is triggered and we emit an UPDATE without any `WHERE` clause at all. This fixes the issue by making sure to get the primary keys from the realized row rather than from the result of `(before-update (merge realized-row changes))`. I also added tests as well as an assertion that a primary key is actually present, since its absence is so dangerous.
2103be5
to
af985fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it's changing a lot of behavior, the old code realized the row and then used that as row
everywhere, the new code keeps realized-row
separately but doesn't thread that thru to everything else like it did before.
It probably doesn't make a difference since under the hood the underlying transient Row
object should know it was already realized elsewhere and return the realized version but I think by making the change I suggested it would make the code a little clearer and eliminate a little bit of overhead
Co-authored-by: Cam Saul <[email protected]>
Doh, yeah - sorry about that! |
This test passes for me on MariADB 11.3 but fails on MariaDB 11.4, looks like they just changed the error message slightly.
@camsaul it looks like MariaDB has changed the error format from
vs
in the test case between 11.3 and 11.4 - locally things pass if I run |
In a very precise condition, we would emit an
UPDATE
clause withoutany
WHERE
condition at all:the
before-update
method's result does not have a primary keythe
where
clause in anupdate!
call matches multiple rowssome part of the update map will change all matched rows
another part of the update map will change only a subset of matched
rows
If all these conditions are met, the bug is triggered and we emit an
UPDATE without any
WHERE
clause at all.This fixes the issue by making sure to get the primary keys from the
realized row rather than from the result of
(before-update (merge realized-row changes))
. I also added tests aswell as an assertion that a primary key is actually present, since its
absence is so dangerous.