Skip to content

Commit 7e9519f

Browse files
Error codegen (#162)
# Why The encode_type function was incorrectly propagating the RiverError base class to all nested types when generating error schemas. This meant that if an error type had nested object properties (e.g., a field containing user details or metadata), those nested objects would also inherit from RiverError instead of BaseModel. This is incorrect because only the top-level error types should inherit from RiverError - nested properties are just data structures, not errors themselves. # What changed Modified the encode_type function to pass "BaseModel" instead of the current base_model value when recursively processing object properties (line 538). This is done conditionally only when the current base_model is "RiverError". The fix ensures that: Top-level error types and union members of error types continue to inherit from RiverError Nested properties within those error types inherit from BaseModel All other base model types ("TypedDict", "BaseModel") maintain their existing behavior unchanged
1 parent c5e05ce commit 7e9519f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/replit_river/codegen/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
535535
type_name, _, contents, _ = encode_type(
536536
prop,
537537
TypeName(prefix.value + name.title()),
538-
base_model,
538+
"BaseModel" if base_model == "RiverError" else base_model,
539539
in_module,
540540
permit_unknown_members=permit_unknown_members,
541541
)

tests/v1/codegen/snapshot/snapshots/test_unknown_enum/enumService/needsEnumObject.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,19 @@ class NeedsenumobjectOutput(BaseModel):
104104
)
105105

106106

107-
class NeedsenumobjectErrorsFooAnyOf_0(RiverError):
107+
class NeedsenumobjectErrorsFooAnyOf_0(BaseModel):
108108
beep: Literal["err_first"] | None = None
109109

110110

111-
class NeedsenumobjectErrorsFooAnyOf_1(RiverError):
111+
class NeedsenumobjectErrorsFooAnyOf_1(BaseModel):
112112
borp: Literal["err_second"] | None = None
113113

114114

115115
NeedsenumobjectErrorsFoo = Annotated[
116116
NeedsenumobjectErrorsFooAnyOf_0
117117
| NeedsenumobjectErrorsFooAnyOf_1
118-
| RiverUnknownError,
119-
WrapValidator(translate_unknown_error),
118+
| RiverUnknownValue,
119+
WrapValidator(translate_unknown_value),
120120
]
121121

122122

0 commit comments

Comments
 (0)