Skip to content

Commit

Permalink
fix: handle nil CompositeIDProperty value during database insert (#628)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bwdmr authored Feb 7, 2025
1 parent ead3cee commit dd5a92d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/FluentKit/Properties/CompositeID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ extension CompositeIDProperty: AnyDatabaseProperty {
}

public func input(to input: any DatabaseInput) {
self.value!.input(to: input)
if let value = self.value {
value.input(to: input)
}
}

public func output(from output: any DatabaseOutput) throws {
Expand Down

0 comments on commit dd5a92d

Please sign in to comment.