Skip to content

fix: Correct the sessionId parameter in ScoreBody when calling langfuse.create_score(...)#1580

Closed
billotais wants to merge 1 commit intolangfuse:mainfrom
billotais:fix/create-score-session-id-parameter
Closed

fix: Correct the sessionId parameter in ScoreBody when calling langfuse.create_score(...)#1580
billotais wants to merge 1 commit intolangfuse:mainfrom
billotais:fix/create-score-session-id-parameter

Conversation

@billotais
Copy link

@billotais billotais commented Mar 26, 2026

Fixes langfuse/langfuse#12812

Disclaimer: Experimental PR review

Greptile Summary

This PR fixes a one-line bug in Langfuse.create_score() where ScoreBody was constructed with the Python field name session_id= instead of the required Pydantic alias sessionId=.

Why the original code was broken:

  • ScoreBody.session_id is declared as Annotated[Optional[str], FieldMetadata(alias="sessionId")].
  • ScoreBody.model_config does not set populate_by_name=True.
  • Without that flag, Pydantic v2 only accepts the alias form in __init__. Because extra="allow" is also set on ScoreBody, passing session_id=value was silently stored as an extra field rather than setting the actual field — so sessionId was always serialised as null in the ingestion payload.

What the fix does:

  • Changes session_id=session_idsessionId=session_id, bringing it in line with all other aliased fields in the same constructor call (traceId, observationId, datasetRunId, dataType, configId).

The change is minimal, targeted, and correct with no side effects.

Confidence Score: 5/5

Safe to merge — single-line targeted bug fix with no behavioural changes beyond correcting the missing sessionId field in score ingestion payloads.

The change is a one-line fix that corrects a clear Pydantic alias misuse. It matches the established pattern of every other field in the same constructor call, has no impact on any other code path, and directly resolves the linked issue.

No files require special attention.

Important Files Changed

Filename Overview
langfuse/_client/client.py Single-line fix: changes session_id= to sessionId= when constructing ScoreBody, making it consistent with every other aliased field and correctly populating the Pydantic alias field.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Langfuse
    participant ScoreBody
    participant IngestionQueue

    Caller->>Langfuse: create_score(session_id=..., trace_id=..., name=..., value=...)
    Langfuse->>ScoreBody: ScoreBody(sessionId=session_id, traceId=trace_id, ...)
    Note over ScoreBody: Pydantic validates via alias<br/>(sessionId, not session_id)
    ScoreBody-->>Langfuse: validated body
    Langfuse->>IngestionQueue: add_score_task({type: "score-create", body: ScoreBody})
    IngestionQueue-->>Caller: (async, no return value)
Loading

Reviews (1): Last reviewed commit: "Fix langfuse.create_score() by replacing..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@CLAassistant
Copy link

CLAassistant commented Mar 26, 2026

CLA assistant check
All committers have signed the CLA.

@billotais billotais marked this pull request as ready for review March 26, 2026 17:18
Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

new_body = ScoreBody(
id=score_id,
session_id=session_id,
sessionId=session_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Fix looks correct — alias required without populate_by_name

ScoreBody.session_id is declared with FieldMetadata(alias="sessionId"), and ScoreBody.model_config does not include populate_by_name=True. In Pydantic v2, without that flag, the constructor only accepts the alias form. Passing session_id=session_id (the Python field name) was silently stored as an extra field (because extra="allow" is set on ScoreBody) instead of populating the intended session_id / sessionId field — meaning sessionId was always sent as null to the API.

The change to sessionId=session_id is consistent with every other aliased field in the same constructor call (traceId, observationId, datasetRunId, dataType, configId) and is the correct fix.

@hassiebp
Copy link
Contributor

Thanks for raising this, this has been fixed already on main 👍🏾

@hassiebp hassiebp closed this Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: session_id not working on langfuse.create_score(...)

3 participants