Fix the Python list_sessions docstring example to use session_id - #2099
Conversation
The Example block in CopilotClient.list_sessions printed
session.sessionId, but list_sessions returns list[SessionMetadata], and
that dataclass declares session_id. sessionId exists only as the wire
key, mapped to session_id inside SessionMetadata.from_dict/to_dict, so
anyone copying the documented example hit:
AttributeError: 'SessionMetadata' object has no attribute 'sessionId'
Use the attribute the returned dataclass actually declares. The Go and
.NET bindings already document this method with their own idiomatic
spelling of the same field.
Docstring text only: no public API, behavior, or wire format change.
There was a problem hiding this comment.
Pull request overview
Corrects the Python list_sessions docstring to use the actual SessionMetadata attribute.
Changes:
- Replaces
sessionIdwithsession_idin the example.
Show a summary per file
| File | Description |
|---|---|
python/copilot/client.py |
Fixes the documented session ID access. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Medium
SDK Consistency Review ✅This PR makes a single-line documentation fix in No cross-SDK consistency issues identified. This is a Python-specific doc correction that does not affect other SDK implementations. Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
SteveSandersonMS
left a comment
There was a problem hiding this comment.
Validated the Python API mapping and reproduced both the broken camelCase access and corrected snake_case access with Python 3.12. The change is necessary, sufficient, and minimal.
Fixes #2098
What was wrong
The
Example:block in theCopilotClient.list_sessionsdocstring printedsession.sessionId.list_sessionsreturnslist[SessionMetadata], and that dataclass declaressession_id;sessionIdexists only as the wire key, mapped tosession_idinsideSessionMetadata.from_dict/to_dict. There is nosessionIdproperty, alias, or__getattr__fallback, so anyone copying the documented example hitAttributeError.The change
Example: >>> sessions = await client.list_sessions() >>> for session in sessions: - ... print(f"Session: {session.sessionId}") + ... print(f"Session: {session.session_id}")One token, in the docstring text of a hand-written binding source file. No public API, behavior,
schema, or wire format change; no generated file is touched.
Why
session_idis the right spellingSessionMetadatadeclaressession_idand neversessionId.session_idon exactly this return value(
python/e2e/test_session_e2e.py).SessionMetadataSnapshotalso usessession_id, and the Pythoncode generator converts every property to snake_case.
get_session_metadataalready documents the same object correctly,as
metadata.start_time.The alternatives -- adding a
sessionIdalias, or renaming the dataclass field -- would bothchange the public Python API, so correcting the example is the minimal correct fix.
Reproduction
Against the published package, with no server, model, or credentials:
Before:
After: the documented example prints
Session: abc-123.I also checked the shipped docstring itself, by parsing the example out of the installed
package's
CopilotClient.list_sessions.__doc__and executing it: it raisesAttributeErrorbefore the change and prints the session id after.
Checks run
From
python/, matching.github/workflows/python-sdk-tests.yml:ruff check .-- passes.ty check copilot-- passes (2 pre-existing warnings, neither near this line).ruff format --check copilot/client.py-- already formatted; the changed line is 59 charactersagainst a 100-character limit, so
docstring-code-formathas nothing to reflow.pytest-- per-test results are identical before and after the change, andtest_should_list_sessionspasses. The few end-to-end tests that fail in my local environmentfail the same way on an unmodified tree.
Scope
Python only. Go already documents this method as
session.SessionID(go/client.go) and .NET assession.SessionId(dotnet/src/Client.cs), so the other bindings are correct as they stand andno cross-binding change is needed.