Repository navigation
Commit 587baa7
authored
fix: relax enum validation to tolerate unknown API values (#941)
Enum fields in the generated models were strict `Literal[...]` aliases
in `_literals.py`. Because every API response is Pydantic-validated, any
unknown or newly introduced enum value the platform sent raised a
`ValidationError` and broke the whole call.
The postprocess step now emits an open literal `Literal[...] | str` for
each shared enum alias, so unknown values validate while the known
members stay as autocomplete hints. Discriminated unions are unaffected
— they use inline single-value `Literal[...]`, not the shared aliases.
Changes:
- `scripts/postprocess_generated_models.py`: emit `Literal[...] | str`;
broaden the literal-alias detection (`_is_literal_expr`) so a widened
alias is still recognized and moved into `_literals.py`.
- `src/apify_client/_literals.py`: regenerated — all 11 aliases widened
(members unchanged).
- `pyproject.toml`: ignore `PYI051` for `_literals.py` (the
redundant-looking `Literal[...] | str` union is deliberate).
- `tests/unit/test_postprocess_generated_models.py`: cover the open
union end-to-end, plus a negative case for non-`str` unions.
Closes #9311 parent 1b0290a commit 587baa7
4 files changed
Lines changed: 619 additions & 484 deletions
File tree
- scripts
- src/apify_client
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
173 | 176 | | |
174 | 177 | | |
175 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
115 | | - | |
| 117 | + | |
116 | 118 | | |
117 | 119 | | |
118 | | - | |
119 | | - | |
120 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
| |||
146 | 150 | | |
147 | 151 | | |
148 | 152 | | |
149 | | - | |
| 153 | + | |
150 | 154 | | |
151 | 155 | | |
152 | 156 | | |
| |||
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
182 | 199 | | |
183 | | - | |
| 200 | + | |
184 | 201 | | |
185 | 202 | | |
186 | 203 | | |
187 | 204 | | |
188 | | - | |
189 | | - | |
190 | | - | |
| 205 | + | |
191 | 206 | | |
192 | 207 | | |
193 | 208 | | |
| |||
0 commit comments