Skip to content

Commit f2bb2f9

Browse files
committed
store/postgres: Add test for inserts when all fulltext fields are null
1 parent e8d49ea commit f2bb2f9

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

store/postgres/src/relational_queries.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,7 @@ impl<'a> InsertQuery<'a> {
10551055
.cloned()
10561056
.collect::<Vec<Value>>();
10571057
if !fulltext_field_values.is_empty() {
1058-
entity.insert(
1059-
column.field.to_string(),
1060-
Value::List(fulltext_field_values),
1061-
);
1058+
entity.insert(column.field.to_string(), Value::List(fulltext_field_values));
10621059
}
10631060
}
10641061
None => (),

store/postgres/tests/relational.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,22 @@ const THINGS_GQL: &str = r#"
3232
]
3333
}
3434
]
35+
) @fulltext(
36+
name: "nullableStringsSearch"
37+
language: en
38+
algorithm: rank
39+
include: [
40+
{
41+
entity: "NullableStrings",
42+
fields: [
43+
{ name: "name"},
44+
{ name: "description"},
45+
{ name: "test"},
46+
]
47+
}
48+
]
3549
)
50+
3651
type Thing @entity {
3752
id: ID!
3853
bigThing: Thing!
@@ -87,6 +102,13 @@ const THINGS_GQL: &str = r#"
87102
favorite_color: Color,
88103
drinks: [String!]
89104
}
105+
106+
type NullableStrings @entity {
107+
id: ID!,
108+
name: String,
109+
description: String,
110+
test: String
111+
}
90112
"#;
91113

92114
const SCHEMA_NAME: &str = "layout";
@@ -143,6 +165,12 @@ lazy_static! {
143165
entity.set("__typename", "Scalar");
144166
entity
145167
};
168+
static ref EMPTY_NULLABLESTRINGS_ENTITY: Entity = {
169+
let mut entity = Entity::new();
170+
entity.set("id", "one");
171+
entity.set("__typename", "NullableStrings");
172+
entity
173+
};
146174
}
147175

148176
/// Removes test data from the database behind the store.
@@ -418,6 +446,27 @@ fn find() {
418446
});
419447
}
420448

449+
#[test]
450+
fn insert_null_fulltext_fields() {
451+
run_test(|conn, layout| -> Result<(), ()> {
452+
insert_entity(
453+
&conn,
454+
&layout,
455+
"NullableStrings",
456+
EMPTY_NULLABLESTRINGS_ENTITY.clone(),
457+
);
458+
459+
// Find entity with null string values
460+
let entity = layout
461+
.find(conn, "NullableStrings", "one", BLOCK_NUMBER_MAX)
462+
.expect("Failed to read NullableStrings[one]")
463+
.unwrap();
464+
assert_entity_eq!(scrub(&*EMPTY_NULLABLESTRINGS_ENTITY), entity);
465+
466+
Ok(())
467+
});
468+
}
469+
421470
#[test]
422471
fn update() {
423472
run_test(|conn, layout| -> Result<(), ()> {

0 commit comments

Comments
 (0)