Troubleshooting¶
Common issues and how to resolve them.
Known Issues¶
- Partial encryption:
envdrift lockcould encrypt combined files (like.env.production) and make non-sensitive values unreadable. Fix: lock now skips.clearand combined files; useenvdrift pushfor partial encryption workflows on older versions.
Schema Validation Issues¶
"Module not found" when validating¶
Problem:
Solution:
- Check the module path is correct (use
:to separate module from class) - Use
--service-dirto add the correct directory to Python path
# Wrong
envdrift validate .env --schema config.settings.Settings
# Correct
envdrift validate .env --schema config.settings:Settings
# With service directory
envdrift validate .env --schema config:Settings --service-dir ./backend
Settings class instantiates on import¶
Problem:
This happens when your settings module creates a Settings() instance at import time.
Solution:
Guard the instantiation:
import os
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
DATABASE_URL: str
# Guard against import during schema extraction
if not os.getenv("ENVDRIFT_SCHEMA_EXTRACTION"):
settings = Settings()
"Extra fields not permitted"¶
Problem:
Solution:
Either add the variable to your schema or change the extra setting:
class Settings(BaseSettings):
model_config = SettingsConfigDict(
extra="ignore" # or "allow" to silence the warning
)
Encryption Issues¶
"dotenvx not found"¶
Problem:
Solution:
Install dotenvx:
# macOS
brew install dotenvx/brew/dotenvx
# npm
npm install -g @dotenvx/dotenvx
# Or enable auto-install in config
"sops not found"¶
Problem:
Solution:
Install SOPS:
# macOS
brew install sops
# Linux
wget https://github.com/getsops/sops/releases/download/v3.8.1/sops-v3.8.1.linux.amd64 -O /usr/local/bin/sops
chmod +x /usr/local/bin/sops
"Failed to decrypt: no key found"¶
Problem:
Causes and solutions:
- Missing .env.keys file — Run
envdrift syncto fetch keys from vault - Wrong key — The file was encrypted with a different key
- SOPS: Missing age key — Set
SOPS_AGE_KEY_FILEor add key to~/.config/sops/age/keys.txt
# For dotenvx
envdrift sync # Fetches keys from vault
# For SOPS with age
export SOPS_AGE_KEY_FILE=~/.config/sops/age/keys.txt
"File is not encrypted"¶
Problem:
Solution:
The file wasn't encrypted. Run encrypt:
Vault Issues¶
Azure: "DefaultAzureCredential failed"¶
Problem:
Solutions:
- Login with Azure CLI:
az login - Set environment variables:
- Check you have access to the Key Vault in Azure portal
AWS: "Unable to locate credentials"¶
Problem:
Solutions:
- Configure AWS CLI:
aws configure - Set environment variables:
- In CI, use OIDC or IAM roles
HashiCorp: "permission denied"¶
Problem:
Solutions:
- Check your token has the correct policies
- Ensure the token hasn't expired
- Verify the secret path is correct (including
secret/data/prefix for KV v2)
GCP: "Could not automatically determine credentials"¶
Problem:
Solutions:
- Login with gcloud:
gcloud auth application-default login - Set service account key:
"Secret not found"¶
Problem:
Solutions:
- Check the secret name matches exactly (case-sensitive)
- Verify the secret exists: check vault UI or CLI
- Push the secret first:
envdrift vault-push . myapp-key
Pre-commit Hook Issues¶
Hook doesn't run¶
Problem:
Pre-commit skips envdrift hooks.
Solution:
Ensure the hook is properly configured:
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: envdrift-validate
name: Validate .env files
entry: envdrift validate
args: [".env.production", "--schema", "config:Settings", "--ci"]
language: system
files: ^\.env\.production$
pass_filenames: false
"envdrift: command not found" in pre-commit¶
Problem:
Pre-commit can't find envdrift.
Solution:
Use the full path or ensure it's in PATH:
CI/CD Issues¶
Validation passes locally but fails in CI¶
Causes:
- Different Python version — Schema behaves differently
- Missing dependencies — Install with
pip install envdrift[vault] - Different working directory — Use absolute paths or
--service-dir
Exit code is always 0¶
Problem:
Pipeline doesn't fail on validation errors.
Solution:
Add --ci flag:
Can't decrypt in CI¶
Problem:
Solutions:
- Store the private key as a CI secret
- Use vault sync with CI credentials
- For SOPS, configure KMS access for the CI runner
# GitHub Actions example
- name: Decrypt env
env:
DOTENV_PRIVATE_KEY: ${{ secrets.DOTENV_PRIVATE_KEY }}
run: |
echo "DOTENV_PRIVATE_KEY=$DOTENV_PRIVATE_KEY" > .env.keys
envdrift decrypt .env.production
Performance Issues¶
Slow schema loading¶
Problem:
envdrift validate takes a long time to start.
Causes:
- Heavy imports in your settings module
- Database connections at import time
Solution:
Guard expensive operations:
import os
if not os.getenv("ENVDRIFT_SCHEMA_EXTRACTION"):
# Expensive imports or operations here
from myapp.database import engine
Getting Help¶
If you're still stuck:
- Run with
--verbosefor more details - Check the FAQ
- Search GitHub Issues
- Open a new issue with reproduction steps