Make referenced optional Python RPC requests omittable - #2556
Open
kondv wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Two moderate required-null handling issues remain unresolved in Python code generation.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Enables omission of Python RPC request objects when allowed by the original schema while preserving required nullable fields.
Changes:
- Adds draft-2019-09 schema validation for request optionality.
- Regenerates Python RPC APIs and adds regression tests.
- Updates dependencies and quota documentation.
File summaries
| File | Review |
|---|---|
scripts/codegen/python.ts |
Two moderate issues: required nulls are dropped in optional session requests, and required opaque-JSON fields remain optional. |
scripts/codegen/package.json |
Adds AJV dependency. |
scripts/codegen/package-lock.json |
Locks codegen dependencies. |
python/test_rpc_generated.py |
Adds generated signature and serialization tests. |
python/copilot/generated/rpc.py |
Updates generated Python RPC models and methods. |
nodejs/test/python-codegen.test.ts |
Tests schema evaluation and code generation. |
nodejs/package.json |
Adds AJV for codegen tests. |
nodejs/package-lock.json |
Locks test dependencies. |
docs/features/usage-and-billing.md |
Documents argument-free quota retrieval. |
Review details
Files not reviewed (2)
- nodejs/package-lock.json: Generated file
- scripts/codegen/package-lock.json: Generated file
Suppressed comments (1)
scripts/codegen/python.ts:3957
- The server-method path has the same optional-wrapper/required-nullable interaction: filtering
Nonehere drops a required field when the request object is supplied explicitly. Selectparams.to_dict()whenpreserveRequiredNullsis true, while retaining{}for an omitted request.
if (paramsOptional) {
lines.push(` params_dict = {k: v for k, v in params.to_dict().items() if v is not None} if params is not None else {}`);
} else if (preserveRequiredNulls) {
lines.push(` params_dict = params.to_dict()`);
- Files reviewed: 6/9 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
kondv
force-pushed
the
dev/kondv/python-get-quota-optional
branch
from
September 7, 2026 12:45
eb61822 to
fd63cf1
Compare
`account.getQuota` declares its params as a `$ref` to `AccountGetQuotaRequest`, whose referenced schema already carries the Zod optional wrapper. The Python generator's optional-params check only inspected the unresolved `$ref`, so the generated method required an argument that callers have no values to supply. Resolve the params schema before the existing wrapper check so referenced optional requests are detected the same way inline ones already are.
kondv
force-pushed
the
dev/kondv/python-get-quota-optional
branch
from
September 8, 2026 16:47
fd63cf1 to
d5da672
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1946
Problem
account.getQuotadeclares its params as a$reftoAccountGetQuotaRequest, and that referenced definition already carries the optional-request wrapperanyOf: [{ not: {} }, { ... }]. The Python generator's optional-params check only inspected the unresolved$ref, so it never saw the wrapper and emitted a required parameter:Callers had no values to supply, so the only workaround was to pass an empty request object.
Change
Resolve the params schema before the existing wrapper check, so a wrapper reached through a
$refis detected exactly like an inline one.This corrects the five methods whose requests are declared that way —
models.list,account.getQuota,plugins.marketplaces.refresh,sessions.list, andsessions.stopRemoteControl— and updates the Python quota example that documented the workaround.The change is limited to that lookup. It adds no dependency and no general schema-validity inference, and it does not alter required requests, required-nullable fields, dataclass defaults, or how a supplied request is serialized. Other language generators are untouched.
Validation
npm run generate:python, rerun to confirm byte-identical outputpython/test_rpc_generated.py— 12 passing; full Python unit suite — 407 passingnodejsnpm run typecheck;shared-codegen,typescript-codegen,client-api-codegen— 28 passingruff checkandruff format --checkmainraisedServerAccountApi.get_quota() missing 1 required positional argument: 'params', matching the report.chat,completions, andpremium_interactions.AccountGetQuotaRequest()still succeeded, and required-paramsaccount.loginstill rejected omission.