pydantic / bump-pydantic

Convert Pydantic from V1 to V2 ♻
MIT License
303 stars 24 forks source link

env -> validation_alias? #125

Closed berzi closed 12 months ago

berzi commented 1 year ago

Hi. This is potentially just a question:

I've noticed bump-pydantic converted my instances of Field(..., env="SOME_ENV") to Field(validation_alias="SOME_ENV").

The documentation for the parameter isn't really illuminating:

'Whitelist' validation step. The field will be the single one allowed by the alias or set of aliases defined.

From its name I can infer that it just defines an alternative name for the field. However, what env used to do was take the value for the field from the environment variable SOME_ENV. Is this still the case with validation_alias? If not, I would frankly avoid "autofixing" this in bump-pydantic, since it's basically guaranteed to generate hard to debug errors. At most what I would do would be to yield an error the user can see in the logs, then they'd be aware of the problem, but if the previous functionality has been removed and must be implemented manually, then changing things (semi-)silently does more harm than good.
If the functionality has stayed in place then I have qualms with Pydantic's own documentation and name for this parameter, but that's a story for another repo.

Kludex commented 12 months ago

Is this still the case with validation_alias?

Yes.

See Environment variable names for more information.