Commit d7c0455
fix(validation): reject None in validate() and validate_json()
The non-discriminated union was built with
reduce(or_, non_discriminated_models, None)
whose None initializer made the resulting union None | Segment | ..., so
validate(None) and validate_json("null") returned successfully instead
of raising ValidationError.
Guard the empty case instead, matching what the CLI's equivalent code in
overture-schema-cli already does. Three annotation details follow from
that: the generator is materialized into a tuple because a generator's
truthiness cannot be tested for emptiness; non_discriminated_union
widens to type[BaseModel] | UnionType | None because reduce over a
single-element tuple returns the bare model type; and model_union gets
an explicit type[BaseModel] | UnionType declaration, because mypy infers
a branch variable from its first assignment and so read the narrower
UnionType off the both-present branch.
The non-discriminated bucket is non-empty in practice: Segment is an
Annotated discriminated union rather than a class, so it fails
_can_discriminate's isinstance(model_class, type) gate.
Tests assert both directions -- the two null forms raise, and a genuine
feature still round-trips -- so a regression that broke the adapter into
rejecting everything could not pass the negative tests by accident.
Signed-off-by: Seth Fitzsimmons <seth@mojodna.net>1 parent 75278d8 commit d7c0455
3 files changed
Lines changed: 39 additions & 4 deletions
File tree
- packages/overture-schema-validation
- changelog.d
- src/overture/schema/validation
- tests
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
83 | | - | |
| 82 | + | |
84 | 83 | | |
85 | 84 | | |
86 | | - | |
87 | | - | |
| 85 | + | |
| 86 | + | |
88 | 87 | | |
89 | 88 | | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
0 commit comments