Skip to content

Commit 8f46d23

Browse files
fix workbench update
1 parent da4141e commit 8f46d23

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

packages/postgres-database/src/simcore_postgres_database/utils_projects_nodes.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,25 @@ async def update(
181181
Raises:
182182
ProjectsNodesNodeNotFound: _description_
183183
"""
184-
update_stmt = (
185-
projects_nodes.update()
186-
.values(**values)
187-
.where(
188-
(projects_nodes.c.project_uuid == f"{self.project_uuid}")
189-
& (projects_nodes.c.node_id == f"{node_id}")
190-
)
191-
.returning(
192-
*[c for c in projects_nodes.c if c is not projects_nodes.c.project_uuid]
193-
)
184+
# Build the insert statement
185+
stmt = pg_insert(projects_nodes).values(
186+
project_uuid=self.project_uuid,
187+
node_id=node_id,
188+
**values,
189+
)
190+
191+
# Define the conflict target and update if there is a conflict
192+
stmt = stmt.on_conflict_do_update(
193+
index_elements=[
194+
"project_uuid",
195+
"node_id",
196+
], # The columns that define the conflict
197+
set_=values, # Columns to be updated if there's a conflict
198+
)
199+
stmt = stmt.returning(
200+
*[c for c in projects_nodes.c if c is not projects_nodes.c.project_uuid]
194201
)
195-
result = await connection.execute(update_stmt)
202+
result = await connection.execute(stmt)
196203
row = await result.first()
197204
if not row:
198205
raise ProjectNodesNodeNotFoundError(

0 commit comments

Comments
 (0)