Skip to content

Commit 5218009

Browse files
authored
Merge pull request #534 from supabase/fix_533
fix #533 in which a default arg was marked as required
2 parents eeafeda + d999536 commit 5218009

File tree

4 files changed

+555
-2
lines changed

4 files changed

+555
-2
lines changed

docs/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@
8484
## 1.5.6
8585
- feature: add support for filtering on array column types using `contains`, `containedBy`, `overlaps`, `is`, `eq`
8686

87-
8887
## master
88+
- bugfix: UDF argument with a complex default expression was marked as required

src/sql_types.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,12 @@ impl<'a> ArgsIterator<'a> {
263263

264264
fn sql_to_graphql_default(default_str: &str, type_oid: u32) -> Option<DefaultValue> {
265265
let trimmed = default_str.trim();
266+
266267
if trimmed.starts_with("NULL::") {
267268
return Some(DefaultValue::Null);
268269
}
269-
match type_oid {
270+
271+
let res = match type_oid {
270272
21 | 23 => trimmed
271273
.parse::<i32>()
272274
.ok()
@@ -283,6 +285,16 @@ impl<'a> ArgsIterator<'a> {
283285
DefaultValue::NonNull(format!("\"{}\"", i.trim_matches(',').trim_matches('\'')))
284286
}),
285287
_ => None,
288+
};
289+
290+
// return the non-parsed value as default if for whatever reason the default value can't
291+
// be parsed into a value of the required type. This fixes problems where the default
292+
// is a complex expression like a function call etc. See test/sql/issue_533.sql for
293+
// a test case for this scenario.
294+
if res.is_some() {
295+
res
296+
} else {
297+
Some(DefaultValue::Null)
286298
}
287299
}
288300
}

0 commit comments

Comments
 (0)