Skip to content

Commit

Permalink
Fix prompt clone error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cephalization committed Jan 11, 2025
1 parent fa35ccf commit 09011f3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/phoenix/server/api/mutations/prompt_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,9 @@ async def clone_prompt(self, info: Info[Context, None], input: ClonePromptInput)
new_prompt.prompt_versions = new_versions

session.add(new_prompt)
await session.flush()

try:
await session.commit()
except (PostgreSQLIntegrityError, SQLiteIntegrityError):
raise Conflict(f"A prompt named '{input.name}' already exists")

return to_gql_prompt_from_orm(new_prompt)
5 changes: 4 additions & 1 deletion tests/unit/server/api/mutations/test_prompt_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,5 +976,8 @@ async def test_clone_prompt_fails_with_duplicate_name(
# clone prompt
result = await gql_client.execute(self.CLONE_PROMPT_MUTATION, variables)
assert len(result.errors) == 1
assert "UNIQUE constraint failed: prompts.name" in result.errors[0].message
assert (
f"A prompt named '{variables['input']['name']}' already exists"
in result.errors[0].message
)
assert result.data is None

0 comments on commit 09011f3

Please sign in to comment.