Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path parser rejects Path defaults #228

Closed
timnyborg opened this issue Sep 13, 2021 · 1 comment
Closed

path parser rejects Path defaults #228

timnyborg opened this issue Sep 13, 2021 · 1 comment

Comments

@timnyborg
Copy link

When using env.path to parse a variable, you cannot set the default to a Path variable:

BASE_DIR: Path = Path(__file__).resolve().parent.parent
MEDIA_ROOT: Path = env.path('MEDIA_ROOT', default=BASE_DIR / 'media')

> environs.EnvValidationError: Environment variable "MEDIA_ROOT" invalid: Not a valid string.

Instead you must first cast it back to str:

BASE_DIR: Path = Path(__file__).resolve().parent.parent
MEDIA_ROOT: Path = env.path('MEDIA_ROOT', default=str(BASE_DIR / 'media'))

I think this is a bit counterintuitive, and it works contrary to other parsers like env.dict, which will accept a dict as a default, rather than requiring the string representation of a dict. Happy to try my hand at a preprocess function if it'd be acceptable.

@sloria
Copy link
Owner

sloria commented Oct 4, 2021

Closed by #231

@sloria sloria closed this as completed Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants