prevent generation crash in mixed TS/Python environments and harden s…#101
prevent generation crash in mixed TS/Python environments and harden s…#101
Conversation
…chema/title normalization
eneumann
left a comment
There was a problem hiding this comment.
Thanks for working on this one @palimad!
One concern: this special-case returns bare ReturnType. Can you confirm ReturnType is actually bound in generated __init__.py globals at import time?
Current test asserts -> dict, so it doesn’t exercise the bare ReturnType path. If that name is unresolved, deploy/import can still fail.
|
|
||
| def _normalize_return_type_for_annotation(function_name: str, return_type_name: str) -> str: | ||
| if return_type_name == "ReturnType": | ||
| return "ReturnType" |
There was a problem hiding this comment.
Does bare ReturnType resolve at import time in generated __init__.py?
There was a problem hiding this comment.
Great catch, thanks. I updated the fix so utility types are normalized before Python annotation generation, which removes the bare ReturnType import-time dependency. So generated imports in init should not be part of the resolution path anymore.
|
@eneumann I fixed the mixed TS/Python deploy crash by adding a shared normalization step before Python codegen works with return types. This now converts TS utility-style types like ReturnType, typeof, Promise, Awaited, and TS unions into safe Python-friendly types early in the flow. |
|
|
||
| if type_spec["kind"] == "plain": | ||
| value = type_spec.get("value", "") | ||
| value = normalize_cross_language_type(type_spec.get("value", "")) |
There was a problem hiding this comment.
This now normalizes \Promise<string | null> to str | None, but server wrappers still only use resp.text for exact str and otherwise call resp.json().
https://github.com/polyapi/poly-alpha/issues/4230
This PR fixes a deploy-time crash in mixed TypeScript/Python environments where generated Python annotations could reference a non-existent
ReturnTypemodule attribute. The server function renderer now avoids unsafe namespacing for the specialReturnTypecase, preventingAttributeErrorduring generate flows. It also hardens generation paths against non-string metadata shapes by normalizing schema title/root values and description inputs before string operations. These changes improve resilience of codegen against inconsistent spec payloads. Regression test coverage was updated around theReturnTypeissue.