Skip to content

Commit fcbe72a

Browse files
committed
fix(psl): validate partial index raw predicate arity
Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent 059a7b2 commit fcbe72a

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

psl/parser-database/src/attributes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,16 +640,16 @@ fn parse_where_clause(model_id: crate::ModelId, ctx: &mut Context<'_>) -> Option
640640

641641
/// Parse raw("...") where clause.
642642
fn parse_raw_where_clause(args: &[ast::Argument], ctx: &mut Context<'_>) -> Option<WhereClause> {
643-
let Some(first_arg) = args.first() else {
643+
let [arg] = args else {
644644
ctx.push_attribute_validation_error(
645-
"The `where` argument must be a raw() function with a string argument, e.g. `where: raw(\"status = 'active'\")`.",
645+
"The `where` argument must be a raw() function with exactly one string argument, e.g. `where: raw(\"status = 'active'\")`.",
646646
);
647647
return None;
648648
};
649649

650-
let Some(predicate) = coerce::string(&first_arg.value, ctx.diagnostics) else {
650+
let Some(predicate) = coerce::string(&arg.value, ctx.diagnostics) else {
651651
ctx.push_attribute_validation_error(
652-
"The `where` argument must be a raw() function with a string argument, e.g. `where: raw(\"status = 'active'\")`.",
652+
"The `where` argument must be a raw() function with exactly one string argument, e.g. `where: raw(\"status = 'active'\")`.",
653653
);
654654
return None;
655655
};

psl/psl/tests/attributes/partial_index.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn partial_index_raw_requires_string_argument() {
166166

167167
let err = parse_unwrap_err(&with_header(dml, Provider::Postgres, &["partialIndexes"]));
168168
let expected = expect![[r#"
169-
[1;91merror[0m: [1mError parsing attribute "@unique": The `where` argument must be a raw() function with a string argument, e.g. `where: raw("status = 'active'")`.[0m
169+
[1;91merror[0m: [1mError parsing attribute "@unique": The `where` argument must be a raw() function with exactly one string argument, e.g. `where: raw("status = 'active'")`.[0m
170170
--> schema.prisma:15
171171
 | 
172172
14 | 
@@ -176,6 +176,30 @@ fn partial_index_raw_requires_string_argument() {
176176
expected.assert_eq(&err);
177177
}
178178

179+
#[test]
180+
fn partial_index_raw_rejects_multiple_arguments() {
181+
let dml = indoc! {r#"
182+
model User {
183+
id Int @id
184+
email String
185+
status String
186+
187+
@@unique([email], where: raw("status = 'active'", "email IS NOT NULL"))
188+
}
189+
"#};
190+
191+
let err = parse_unwrap_err(&with_header(dml, Provider::Postgres, &["partialIndexes"]));
192+
let expected = expect![[r#"
193+
error: Error parsing attribute "@unique": The `where` argument must be a raw() function with exactly one string argument, e.g. `where: raw("status = 'active'")`.
194+
--> schema.prisma:15
195+
 | 
196+
14 | 
197+
15 |  @@unique([email], where: raw("status = 'active'", "email IS NOT NULL"))
198+
 | 
199+
"#]];
200+
expected.assert_eq(&err);
201+
}
202+
179203
#[test]
180204
fn partial_index_cannot_have_empty_predicate() {
181205
let dml = indoc! {r#"

0 commit comments

Comments
 (0)