-
-
Notifications
You must be signed in to change notification settings - Fork 117
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: handle nil CompositeIDProperty value during database insert #628
Conversation
The CompositeIDProperty was force-unwrapping its value during database input, which would crash if the value was nil. This could happen during initial inserts where the composite ID is meant to be set by a database trigger. Now checks if value exists before attempting to input it.
How are you encountering this scenario? The composite ID value is default-initialized to avoid exactly this failure mode. |
idkwym, i have a db function and a trigger on insert. |
The auto-initialized composite ID contains no values, so no values are (or can be) generated or sent by Fluent. In short, its presence should not prevent your trigger from filling them in itself. If it is, something else is wrong. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #628 +/- ##
=======================================
Coverage 24.28% 24.28%
=======================================
Files 149 149
Lines 9349 9350 +1
=======================================
+ Hits 2270 2271 +1
Misses 7079 7079
|
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.
Upon further examination, this is actually a valid fix, and avoids a crash in cases where the id of a model with composite ID has been explicitly set to nil
(which was not previously meaningful, but with this change now becomes equivalent to setting it to .init()
). Thanks for the fix and for getting me to take another look!
…or#628) The CompositeIDProperty was force-unwrapping its value during database input, which would crash if the value was nil. This could happen during initial inserts where the composite ID is meant to be set by a database trigger. Now checks if value exists before attempting to input it.
These changes are now available in 1.50.2
The CompositeIDProperty was force-unwrapping its value during database input, which would crash if the value was nil. This could happen during initial inserts where the composite ID is meant to be set by a database trigger. Now checks if value exists before attempting to input it.