Right now, we have some inconsistent behavior in terms of using aliases in validation and serialization.
By default, if an alias or validation_alias is defined on a field, we use the alias for validation. This behavior can be changed by setting populate_by_name to True on the model_config.
Conversely, if an alias or serialization_alias is defined on a field, that alias not used by default for serialization. We must specify by_alias=True in the call to model_dump + other serialization functions.
I propose that in V3:
- We use
alias by default for both validation and serialization
- We add a field (or fields, but ideally just one) to
ConfigDict to support different behavior than the default
This is a breaking change, hence the V3 label.
Requests to change the inconsistent default behavior have been made for a few years, so I'm going to comb through issues and close those so we can centralize discussion here.
Right now, we have some inconsistent behavior in terms of using aliases in validation and serialization.
By default, if an
aliasorvalidation_aliasis defined on a field, we use the alias for validation. This behavior can be changed by settingpopulate_by_nametoTrueon themodel_config.Conversely, if an
aliasorserialization_aliasis defined on a field, that alias not used by default for serialization. We must specifyby_alias=Truein the call tomodel_dump+ other serialization functions.I propose that in V3:
aliasby default for both validation and serializationConfigDictto support different behavior than the defaultThis is a breaking change, hence the
V3label.Requests to change the inconsistent default behavior have been made for a few years, so I'm going to comb through issues and close those so we can centralize discussion here.