Skip to content

Commit 8a5f9b0

Browse files
committed
trace mutations
1 parent a84379c commit 8a5f9b0

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/phoenix/server/api/mutations/trace_annotations_mutations.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from sqlalchemy import delete, insert, select
55
from starlette.requests import Request
66
from strawberry import UNSET, Info
7+
from strawberry.relay.types import GlobalID
78

89
from phoenix.db import models
910
from phoenix.server.api.auth import IsLocked, IsNotReadOnly
@@ -55,16 +56,13 @@ async def create_trace_annotations(
5556

5657
async with info.context.db() as session:
5758
for idx, (trace_rowid, annotation_input) in enumerate(zip(trace_rowids, input)):
58-
resolved_identifier = annotation_input.identifier or ""
59-
if annotation_input.source == AnnotationSource.APP:
59+
resolved_identifier = ""
60+
if annotation_input.identifier:
61+
resolved_identifier = annotation_input.identifier
62+
elif annotation_input.source == AnnotationSource.APP and user_id is not None:
6063
# Ensure that the annotation has a per-user identifier if submitted via the UI
61-
if user_id is not None:
62-
username = await session.scalar(
63-
select(models.User.username).where(models.User.id == user_id)
64-
)
65-
resolved_identifier = f"px-app:{username}"
66-
else:
67-
resolved_identifier = "px-app"
64+
user_gid = str(GlobalID(type_name="User", node_id=str(user_id)))
65+
resolved_identifier = f"px-app:{user_gid}"
6866
values = {
6967
"trace_rowid": trace_rowid,
7068
"name": annotation_input.name,

0 commit comments

Comments
 (0)