4 ms·
The author makes a great last point about Settings and it’s something I’ve not considered… ever! I wonder if there’s a feature request for this because having a
by scott_w 9mo ago
The author makes a great last point about Settings and it’s something I’ve not considered… ever! I wonder if there’s a feature request for this because having a pre-configured object would be nice for the ability to verify correctness on startup.
- tecoholic 9mo agoI use a project generator tool for a Django project. One of the things it does is generate setting file using string manipulation. I have been trying to think of a more sane way to do this. leverage something like dataclass or Pydantic models to have the typing information available and render a typed and validated Python object. If Django ever made that possible, it would be amazing for dev ex.
- Nextgrid 9mo agohttps://docs.pydantic.dev/latest/concepts/pydantic_settings/ https://docs.pydantic.dev/latest/concepts/pydantic_settings/
- tecoholic 9mo agoInteresting. But it’s not straightforward with Django. So I looked up and found this https://github.com/erhosen-libs/pydjantic https://github.com/erhosen-libs/pydjantic Looks promising and will play with it and see how it helps.
- christophilus 9mo agoIn TypeScript, I use the same validation library (Zod) anywhere I need to validate data. So, I validate my config / environment variables on startup using a Zod schema, I validate my RPC endpoint arguments the same way, etc. I presume you could do the same thing with Django— use Django’s validation feature to validate everything including your config. It’s a nice pattern that gives uniformity and predictability to all of your validation logic.
- scott_w 9mo agoNot really, unfortunately. The thing is, if you mistype a configuration key, Django won’t pick it up. It’ll just leave the default value in place. I also don’t think it does any validation on settings values, it’ll just pass them to whatever uses them. That’s the last time I used it anyway. The situation is worse than that because any plugins usually define their own settings which also don’t validate their contents. I think something centralised that lets you properly scope and validate settings would be nice. If you mistype a key, you’d want an error that it’s just not valid.