Skip to content

Commit ddc540a

Browse files
authored
Fix test_metastore_get_identity flaky test (quickwit-oss#6055)
1 parent b5fc94c commit ddc540a

File tree

1 file changed

+7
-7
lines changed
  • quickwit/quickwit-metastore/src/metastore/postgres

1 file changed

+7
-7
lines changed

quickwit/quickwit-metastore/src/metastore/postgres/metastore.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,15 +1748,15 @@ impl MetastoreService for PostgresqlMetastore {
17481748
&self,
17491749
_: GetClusterIdentityRequest,
17501750
) -> MetastoreResult<GetClusterIdentityResponse> {
1751+
// `ON CONFLICT DO NOTHING RETURNING` returns NULL if no insert happens.
1752+
// To always get the value, we use this pattern:
17511753
let (uuid,) = sqlx::query_as(
17521754
r"
1753-
WITH insert AS (
1754-
INSERT INTO kv (key, value)
1755-
VALUES ('cluster_identity', $1)
1756-
ON CONFLICT (key) DO NOTHING
1757-
)
1758-
SELECT value FROM kv where key = 'cluster_identity';
1759-
",
1755+
INSERT INTO kv (key, value)
1756+
VALUES ('cluster_identity', $1)
1757+
ON CONFLICT (key) DO UPDATE SET key = EXCLUDED.key
1758+
RETURNING value
1759+
",
17601760
)
17611761
.bind(Uuid::new_v4().hyphenated().to_string())
17621762
.fetch_one(&self.connection_pool)

0 commit comments

Comments
 (0)