fix(scores): parse session ID correctly#1582
Conversation
|
@claude review |
…on-langfusecreate_score
There was a problem hiding this comment.
LGTM — the field name fix is correct and the change is minimal.
Extended reasoning...
Overview
The PR fixes a field name mismatch in langfuse/_client/client.py where session_id (snake_case) was passed to ScoreBody instead of the correct camelCase sessionId. A minor debug log removal in request.py is also included, along with a new integration test test_create_session_score that exercises the fix.
Security risks
None. This is a field-name bug fix with no auth, crypto, or permission changes.
Level of scrutiny
Low — the change is a one-line rename of a keyword argument to the correct camelCase form that the Pydantic model expects. The intent is clear and the fix is mechanical.
Other factors
The only bugs found are test-quality nits (an unused api_wrapper variable and a leftover print statement in the new test). These are already noted as inline comments and do not affect correctness or CI reliability in a meaningful way. The core fix is straightforward enough to approve.
Disclaimer: Experimental PR review
Greptile Summary
This PR fixes a bug where
session_idwas not serialized correctly when creating scores. InScoreBody, all fields use camelCase alias forms in the constructor (traceId,observationId,datasetRunId, etc.) — the score creation code was the only place using the Python snake_case namesession_id=instead of the aliassessionId=, causing the session ID to be silently dropped or misrouted. The fix aligns it with the existing pattern. A debug log statement is also cleaned up frombatch_post(equivalent logging remains inpost()), and an integration test is added to verify the session-level score round-trip.langfuse/_client/client.py: One-line fix —session_id=session_id→sessionId=session_idin theScoreBodyconstructor calllangfuse/_utils/request.py: Removes redundantlogger.debug("uploading data: %s", kwargs)frombatch_post; the same data is already logged after serialization insidepost()tests/test_core_sdk.py: New integration testtest_create_session_scorecreates a session-scoped score and asserts it is retrievable with the correctsession_id; has minor cleanup items (unusedapi_wrapper, a debugprint, missing blank line)Confidence Score: 5/5
Safe to merge — the core fix is a minimal, correct one-line change aligned with existing patterns; all remaining findings are P2 style issues in the new test
The bug fix itself is straightforward and consistent with every other camelCase field in the same constructor. No P0 or P1 issues were found. The three findings are all minor test-code style issues (unused variable, debug print, missing blank line) that do not affect correctness or reliability.
tests/test_core_sdk.py — minor cleanup (unused api_wrapper, print statement, missing blank line)
Important Files Changed
session_id=session_idtosessionId=session_idinScoreBodyconstructor to use the camelCase alias, consistent with all other fields (traceId,observationId,datasetRunId, etc.)logger.debug("uploading data: %s", kwargs)frombatch_post; equivalent debug logging still exists in the downstreampost()method after serializationtest_create_session_scorevalidates the session-level score fix; has minor style issues: unusedapi_wrappervariable, a leftoverprintstatement, and a missing blank line before the next testSequence Diagram
sequenceDiagram participant Caller participant Langfuse as Langfuse.create_score() participant ScoreBody participant LangfuseClient as LangfuseClient.batch_post() participant API as Langfuse API Caller->>Langfuse: create_score(session_id="s1", name="score", value=1) Langfuse->>ScoreBody: ScoreBody(sessionId="s1", traceId=..., ...) Note over ScoreBody: Field stored via camelCase alias<br/>(consistent with traceId, observationId, etc.) ScoreBody-->>Langfuse: score_body (frozen model) Langfuse->>Langfuse: wrap in event dict {type: "score-create", body: score_body} Langfuse->>LangfuseClient: batch_post(batch=[event]) LangfuseClient->>LangfuseClient: post() — json.dumps via EventSerializer Note over LangfuseClient: dict(by_alias=True) +<br/>convert_and_respect_annotation_metadata<br/>→ {"sessionId": "s1", ...} LangfuseClient->>API: POST /api/public/ingestion API-->>LangfuseClient: 200 OK LangfuseClient-->>Langfuse: responseReviews (1): Last reviewed commit: "fix(scores): parse session ID correctly" | Re-trigger Greptile