Resolve python_version from language_version for backward compat (#2488)

## Summary

- Add `model_validator` to `OptimizeSchema`, `OptimizeSchemaLP`, and
`TestGenSchema` that resolves `python_version` from `language_version`
when the request language is `"python"`
- Old clients sending `python_version` continue to work unchanged
- New clients sending only `language_version` get `python_version`
populated automatically for downstream handlers

This must be deployed **before** the client-side changes that stop
sending `python_version`
(codeflash-ai/codeflash#remove-python-version-field).

Once all clients are updated, `python_version` can be fully removed from
the schemas and handlers.

## Test plan

- [x] Existing schema tests pass
(`tests/optimizer/test_javascript_schema.py`)
- [ ] Verify old clients (sending `python_version`) still work after
deploy
- [ ] Verify new clients (sending only `language_version`) resolve
correctly
This commit is contained in:
Kevin Turcios 2026-03-27 03:19:03 -05:00 committed by GitHub
parent cc4eaf4392
commit f57229cb34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View file

@ -3,8 +3,10 @@
from __future__ import annotations
import enum
from typing import Self
from ninja import Schema
from pydantic import model_validator
class OptimizedCandidateSource(str, enum.Enum):
@ -34,6 +36,13 @@ class OptimizeSchema(Schema):
n_candidates: int = 5 # default value for backward compatibility
is_numerical_code: bool | None = None
@model_validator(mode="after")
def resolve_python_version(self) -> Self:
"""Resolve python_version from language_version for backward compatibility."""
if self.python_version is None and self.language_version is not None and self.language == "python":
self.python_version = self.language_version
return self
class OptimizeSchemaLP(Schema):
source_code: str
@ -49,3 +58,10 @@ class OptimizeSchemaLP(Schema):
model: str | None = None
call_sequence: int | None = None
is_numerical_code: bool | None = None
@model_validator(mode="after")
def resolve_python_version(self) -> Self:
"""Resolve python_version from language_version for backward compatibility."""
if self.python_version is None and self.language_version is not None and self.language == "python":
self.python_version = self.language_version
return self

View file

@ -28,6 +28,13 @@ class TestGenSchema(Schema):
is_numerical_code: bool | None = None
module_system: str | None = None # "esm" or "commonjs" (JS/TS only)
@model_validator(mode="after")
def resolve_python_version(self) -> Self:
"""Resolve python_version from language_version for backward compatibility."""
if self.python_version is None and self.language_version is not None and self.language == "python":
self.python_version = self.language_version
return self
@model_validator(mode="after")
def helper_function_names_validator(self) -> Self:
# To maintain backwards compatibility