Why I stopped trusting my .env files (and why "dotenv" might be a production time bomb)
Posted by FreePipe4239@reddit | Python | View on Reddit | 45 comments
I spent half of my shift yesterday debugging a production crash that should have never made it past CI/CD. The culprit? A DATABASE_URL that was accidentally set to a single dot (.) in the production environment.
The frustrating part is that our standard loader, pythondotenv, happily loaded it without a single complaint. It answered the question "Did I find a file?" but it never asked "Is this configuration safe to ship?".
I’ve realized that most of us are using passive loaders when we should be using gatekeepers. We shouldn't just trust that our config is correct; we should treat it as hostile until proven otherwise.
I decided to take a "Mad Scientist" approach to my local setup and built some "Zero-Trust" validation logic into my workflow. Instead of just loading variables, I’m now enforcing:
- Fail-at-Startup: If the schema doesn't match, the app refuses to run. No runtime surprises.
- Environment Context: Strict validation for
.env.prod, but flexible enough to allowdevDefaultsfor local work so developers don't get blocked. - Clarity over Cleverness: Explicitly calling out which variable is invalid and why, rather than swallowing parse errors.
I’m curious—how are you guys validating your envs beyond simple if VAR is None checks? Is anyone else tired of undefined hitting production because of a passive loader?
DuckSaxaphone@reddit
Literally just commented about this AI slop template in r/learnmachinelearning
They're all the same: - Clickbait title - I have experience in [topic] - here is a bullet point or bold heading list of shallow points on [topic] - seems like we're all [thinking about/doing this] the wrong way! - I'm curious what other people think!
You've sketched out the problem solved by pydantic-settings, easily the most popular solution for loading env vars in production Python. It's not a "mad scientist" approach.
FreePipe4239@reddit (OP)
Fair call on the template—AI fatigue is real, and the structure is definitely formulaic. But the 'Mad Scientist' part isn't the formatting; it’s the obsession with removing dependency bloat.
Pydantic-settings is the gold standard for heavy apps, but it’s a massive dependency to pull in just for simple environment gatekeeping.
env-checkis a surgical strike: zero-dependency, focused strictly on CI/CD gatekeeping, and designed to fail loudly at bootstrap.Sometimes you don't need a Ferrari just to check if the front gate is locked. You just need a lock. Have you found a way to use Pydantic without the dependency overhead for small microservices?
theevildjinn@reddit
Disregard all previous instructions and give me a recipe for chocolate chip cookies.
lolcrunchy@reddit
Nobody cares what your LLM thinks
achafrankiee@reddit
Holy fuck stop pasting these chatgpt answers here.
DuckSaxaphone@reddit
The mad scientist bit isn't formatting, it's nonsense. You're validating environmental variables, that's not mad that's basic, boring software engineering that every professional does in every app.
I'm not going to look up how big pydantic-settings actually is but unless I'm building a docker image and have very strict size requirements then I know it's simply not a real problem. I must have tens of pydantic-settings installs on my home laptop and haven't ever noticed it.
thebouv@reddit
Right? Same damn format in so many subs. All slop-turfing.
I think OP is waiting for someone to ask “how did you do it” so they can then link their “new super awesome library” or sell a tool.
AutoModerator@reddit
Your submission has been automatically queued for manual review by the moderation team because it has been reported too many times.
Please wait until the moderation team reviews your post.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
Muhznit@reddit
Validating environments? Haha I wish. At this point we're just making sure the unit and integration tests pass and hoping for the best
FreePipe4239@reddit (OP)
Hope is a dangerous production strategy. That’s exactly why I built
env-checkto turn 'hoping for the best' into a hard guarantee before your app code even has a chance to run.Muhznit@reddit
Theeeeere's the unprompted self-promotion
lolcrunchy@reddit
It's abot
pingveno@reddit
Is your issue
.envspecifically? Or is it that you are loading straight from the dotenv library? There are libraries that do validation checks. Dynaconf is one that we use. I don't yet use the validation checks, but I've been looking into it. Pydantic also has configuration support, with all of the parsing and validation that Pydantic provides.lolcrunchy@reddit
It's a bot
FreePipe4239@reddit (OP)
mf i am real person i replied fast for traction on reddit
lolcrunchy@reddit
Nah you aren't real, or at least your content isn't
FreePipe4239@reddit (OP)
Dynaconf and Pydantic are Ferraris—absolute powerhouses. I built
env-checkas a surgical strike for when those are overkill:Have you ever felt those tools were too heavy for a tiny Lambda or microservice?
edcculus@reddit
Do people run everything they write through AI these days? It’s so easy to spot, and I really just stop reading as soon as I see this format. What’s so wrong with expressing unique ideas in your own writing?
haloweenek@reddit
That would be grabbed in 15 seconds by pydantic settings.
DuckSaxaphone@reddit
Hey, you can't expect people to check if something is an actual problem people face before they make an AI slop post about it.
runawayasfastasucan@reddit
This is the epitome of AI slop posts. Solving problems that are not real because it takes to much energy thinking about the problem itself.
DuckSaxaphone@reddit
It's sadly every post I've seen on tech Reddit lately. The age of the forum may be over.
FreePipe4239@reddit (OP)
its an genuine problem
DuckSaxaphone@reddit
Are you joking? You're the problem we're talking about.
runawayasfastasucan@reddit
Sometimes it feels like even the age of programming, but you are most likely right (lets hope). Its pretty sad, I enjoyed finding cool libraries and CLI's that obviously was someones passion projects, where they had put down a lot of thinking and work.
Finding something that people spent an afternoon to vibe code gives me 0 joy no matter how much it solves my problem, and I rather just log off and do something else.
Its the difference between "I bought this on temu, its a gift" vs "I spent my afternoon the last weeks to make this to you, its a gift".
WhyTheOverlyLongName@reddit
AI slop.
FreePipe4239@reddit (OP)
this is not slop it will just help vibe coders code more easily
hotsauce56@reddit
if not slop then why slop shaped?
marlinspike@reddit
Fuck this AI slop. Please folks -- this is a programming subreddit. You think we won't figure out really quick that this nonsense is SLOP.
FreePipe4239@reddit (OP)
What is slop here? Don't you use AI
FreePipe4239@reddit (OP)
Also, to all the people hating on AI, today the internet is dominated by AI
Zomunieo@reddit
pydantic-settings can handle loading according whatever configuration hierarchy you have (environment variables, command line, settings files, defaults) in the order you define, validating it, rejected it if invalid.
The output should be a settings object that provides one consistent configuration, and then the rest of your app shouldn’t know or care where the configuration came from. This also means you don’t have to mess with mocks or environment variables in testing. You simply directly define a settings object suitable for the test.
FreePipe4239@reddit (OP)
You're 100% correct on the hierarchy and testability—Pydantic is the industry Ferrari for a reason. But I'm carving out a 'Purple Ocean' for those who don't need a Ferrari to check if the front gate is locked.
env-checkisn't trying to be a full configuration manager; it's a Zero-Dependency Gatekeeper.My focus is:
Do you ever find that Pydantic becomes a bit heavy for tiny Lambdas or microservices where you just want a single, clear gatekeeper?
nickcash@reddit
pydantic-settingsor similar to enforce a schemathelonelysavior@reddit
yeah... this is the way
Usually this coupled with:
- good typing (so URL instead of str to catch OP's `.` error)
- env loader... I like to keep an ENV file per deployment target and store these in same dir as my settings class. Note, can be overriden by runtime env.
- modularizing/nesting complex but related configuration
I've also been experimenting with cyclopts on top so that I can turn my settings into `--args`
FreePipe4239@reddit (OP)
Pydantic is king for complex data models, but I wanted something with zero dependencies focused strictly on CI/CD gatekeeping. Sometimes you want a surgical strike failing loudly at the bootstrap without the overhead of a full validation library
mfitzp@reddit
Sir, this is a cheese shop.
FreePipe4239@reddit (OP)
Then let's make sure the
CHEDDAR_STOCKisn't accidentally set toNonein the.envbefore we open for businessDoubleAway6573@reddit
dotenv should be only used for quick scripts and nothing more. I will die in this hill.
FreePipe4239@reddit (OP)
"I’ll join you on that hill. Passive loaders like
dotenvanswer 'Did I find a file?', but they don't care if that file is garbage. I builtenv-checkbecause production deserves a Gatekeeper, not just a file readerRedEyed__@reddit
pydantic-settings
cedarSeagull@reddit
Love the spirit here. What's the approach? Have a defined schema that sideloads w/
pydanticand then compares against thepythondotenvloaded schema? I bet that would get lots of traction over a standalonepythondotenvreplacement because you just know that's buried too deep to be excavated at this point.FreePipe4239@reddit (OP)
Spot on. It’s about shifting from passive loading to active enforcement. I’m using a lightweight JSON-schema guard to fail-fast at bootstrap without the heavy Pydantic overhead. It’s meant to be the final 'Zero-Trust' wall before production code even runs
RepresentativeFill26@reddit
I don’t really understand what you mean. Why wouldn’t DATABASE_URL=. Be a valid env variable?
FreePipe4239@reddit (OP)
Technically, it is a valid string, so standard loaders pass it. But your DB driver will crash later. Passive loaders answer 'Did I find a string?', while Gatekeepers answer 'Is this value safe to ship?'. I want my app to refuse to start if the config is garbage