Commit 024b5d0
Fix Enum field by-name lookup to only return actual members (#2902)
* Fix Enum field by-name lookup to only return actual members
Use dict-style access (self.enum[val]) instead of getattr(self.enum, val)
for by-name deserialization. getattr returns any attribute of the Enum
class, not just members. For example, passing "mro" or "__class__" would
return built-in methods/attributes instead of raising a validation error.
The enum item access operator [] only looks up actual enum members,
so non-member attribute names now correctly raise a validation error.
* Add test for Enum field rejecting non-member attributes by name
* Update changelog
---------
Co-authored-by: Jared Deckard <jared@shademaps.com>
Co-authored-by: Steven Loria <git@stevenloria.com>1 parent 252090c commit 024b5d0
3 files changed
Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1947 | 1947 | | |
1948 | 1948 | | |
1949 | 1949 | | |
1950 | | - | |
1951 | | - | |
| 1950 | + | |
| 1951 | + | |
1952 | 1952 | | |
| 1953 | + | |
1953 | 1954 | | |
1954 | 1955 | | |
1955 | 1956 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1197 | 1197 | | |
1198 | 1198 | | |
1199 | 1199 | | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
1200 | 1208 | | |
1201 | 1209 | | |
1202 | 1210 | | |
| |||
0 commit comments