Commit 772ac76
[python] fix TypedDict rendering for template-instantiated models (#11161)
fix #11149
## Why
PR #10439 enabled TypedDict body-overload generation in the default
`dpg` mode. In real Azure mgmt libraries (e.g. `azure-mgmt-netapp`),
this produced dangling `_types.CacheUpdate` references that were absent
from `types.py`, causing an `AttributeError` at import time.
## Root cause
Template-instantiated models all share the *template's*
`crossLanguageDefinitionId`. For example, every
`Azure.ResourceManager.Foundations.ResourceUpdateModel<T, P>`
instantiation (`CacheUpdate`, `VolumeUpdate`,
`ActiveDirectoryConfigUpdate`, ...) carries `clid =
Azure.ResourceManager.Foundations.ResourceUpdateModel`.
The `typeddict_models` dedup keyed the dpg-vs-copy pairing on that
`clid`, so it treated genuinely distinct models as duplicates and
skipped all but the first one. In netapp, `ActiveDirectoryConfigUpdate`
was seen first, so `CacheUpdate` was dropped from `types.py` while still
being referenced via `_types.CacheUpdate`.
## Fix
- Key the dpg-vs-copy pairing on the model `name` instead of
`crossLanguageDefinitionId`. The typeddict copy is a shallow copy of the
source, so it shares the source's name; distinct template instantiations
have distinct names, and model names are unique within a `types.py`
module.
- Harden `_find_existing_typeddict` in preprocess to also match on
`name` (same root cause, tightly coupled).
This keeps TypedDict generation on in `dpg` mode (intentional per
#10439) and just corrects the rendering so referenced TypedDicts
actually land in `types.py`.
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>1 parent 89c1316 commit 772ac76
6 files changed
Lines changed: 584 additions & 29 deletions
File tree
- .chronus/changes
- packages/http-client-python
- generator/pygen
- codegen
- models
- serializers
- preprocess
- tests/unit
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
| |||
Lines changed: 105 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
74 | 148 | | |
75 | 149 | | |
76 | 150 | | |
77 | 151 | | |
78 | | - | |
| 152 | + | |
79 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
80 | 165 | | |
81 | | - | |
82 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
83 | 171 | | |
84 | 172 | | |
85 | | - | |
86 | | - | |
| 173 | + | |
| 174 | + | |
87 | 175 | | |
88 | | - | |
| 176 | + | |
89 | 177 | | |
90 | | - | |
91 | | - | |
| 178 | + | |
| 179 | + | |
92 | 180 | | |
93 | 181 | | |
94 | | - | |
95 | | - | |
| 182 | + | |
96 | 183 | | |
97 | 184 | | |
98 | 185 | | |
99 | 186 | | |
100 | 187 | | |
101 | 188 | | |
102 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
103 | 195 | | |
104 | 196 | | |
105 | 197 | | |
106 | | - | |
| 198 | + | |
| 199 | + | |
107 | 200 | | |
108 | 201 | | |
109 | 202 | | |
| |||
Lines changed: 55 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
310 | | - | |
311 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
312 | 322 | | |
313 | 323 | | |
314 | 324 | | |
| |||
318 | 328 | | |
319 | 329 | | |
320 | 330 | | |
| 331 | + | |
321 | 332 | | |
322 | 333 | | |
323 | 334 | | |
324 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
325 | 375 | | |
326 | 376 | | |
327 | 377 | | |
| |||
376 | 426 | | |
377 | 427 | | |
378 | 428 | | |
379 | | - | |
| 429 | + | |
380 | 430 | | |
381 | 431 | | |
382 | 432 | | |
383 | 433 | | |
384 | 434 | | |
385 | 435 | | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
| 436 | + | |
398 | 437 | | |
399 | 438 | | |
400 | 439 | | |
| |||
407 | 446 | | |
408 | 447 | | |
409 | 448 | | |
410 | | - | |
| 449 | + | |
411 | 450 | | |
412 | 451 | | |
413 | 452 | | |
| |||
420 | 459 | | |
421 | 460 | | |
422 | 461 | | |
423 | | - | |
424 | 462 | | |
425 | 463 | | |
426 | 464 | | |
| |||
0 commit comments