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

Raise FileNotFoundError when the env_file parameter on Config is not valid #2422

Merged
merged 3 commits into from
Jan 20, 2024

Conversation

mathause
Copy link
Contributor

Summary

Addresses #2101

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

-> I think this if ok without doc update. Let me know otherwise.

@Kludex Kludex changed the title raise error on missing env file Raise FileNotFoundError when env file is missing on Config Jan 20, 2024
@Kludex Kludex changed the title Raise FileNotFoundError when env file is missing on Config Raise FileNotFoundError when env_file is missing on Config Jan 20, 2024
@Kludex Kludex changed the title Raise FileNotFoundError when env_file is missing on Config Raise FileNotFoundError when the env_file parameter on Config is not valid Jan 20, 2024
@Kludex Kludex enabled auto-merge (squash) January 20, 2024 12:04
@Kludex Kludex merged commit 13c66c9 into encode:master Jan 20, 2024
5 checks passed
WilliamDEdwards added a commit to CyberfusionIO/Security-TXT-Policy-Server that referenced this pull request Jan 22, 2024
@mathause mathause deleted the error_on_missing_env_file branch January 26, 2024 10:09
@rambo
Copy link

rambo commented Feb 5, 2024

oof, all my docker containers using the old documented pattern are now failing after routine dependency updates.
Maybe the PR checklist should contain checks about breaking things, though in this case OP obviously thought nothing would break. Ref #2446

PeterJCLaw added a commit to PeterJCLaw/code-submitter that referenced this pull request Feb 5, 2024
Changed in: encode/starlette#2422, though
not called out as breaking in the release notes.
nixroxursox pushed a commit to nixroxursox/starlette that referenced this pull request Mar 18, 2024
…s not valid (encode#2422)

* raise error on missing env file

* format

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
br3ndonland added a commit to br3ndonland/fastenv that referenced this pull request Apr 7, 2024
Starlette 0.37 modifies the exception handling behavior of the `Config`
class used for application settings. The `Config` class accepts an
`env_file` arg that can be used to load environment variables from a
"dotenv" (`.env`) file. Previously, if the file was not found, the
`Config` class would silently pass without any exception. In 0.36, the
`Config` class was updated to raise a `FileNotFoundError` exception if
`env_file` was not not found. This was a breaking change but was not
documented as such (encode/starlette#2422, encode/starlette#2446).
In 0.37, the exception handling behavior has been changed again to raise
a warning instead of an exception (encode/starlette#2485), which could
also be a breaking change if users had rewritten their code to catch the
`FileNotFoundError`.

This commit will update the comparisons docs to explain that a warning
will now be raised, and will link to the relevant code changes.
br3ndonland added a commit to br3ndonland/inboard that referenced this pull request Apr 8, 2024
This commit will update/upgrade to
[FastAPI 0.110.1](https://fastapi.tiangolo.com/release-notes/)
and
[Starlette 0.37.2](https://www.starlette.io/release-notes/).
FastAPI 0.110 makes a change to dependencies with `yield` and `except`.
Dependencies must now raise exceptions after `except`. This change is
intended to address memory leak issues and may be a breaking change in
some projects if dependencies with `yield` and `except` used `pass`
instead of `raise`. See the
[FastAPI docs](https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-with-yield/)
for further info. FastAPI 0.110.1 makes a small type annotation change
to the `Depends` dependency class.

Starlette 0.37 modifies the exception handling behavior of the `Config`
class used for application settings. The `Config` class accepts an
`env_file` arg that can be used to load environment variables from a
"dotenv" (`.env`) file. Previously, if the file was not found, the
`Config` class would silently pass without any exception. In 0.36, the
`Config` class was updated to raise a `FileNotFoundError` exception if
`env_file` was not not found. This was a breaking change but was not
documented as such (encode/starlette#2422, encode/starlette#2446).
In 0.37, the exception handling behavior has been changed again to raise
a warning instead of an exception (encode/starlette#2485), which could
also be a breaking change if users had rewritten their code to catch the
`FileNotFoundError`.
See the [fastenv docs](https://fastenv.bws.bio/comparisons#starlette)
for a detailed description of the Starlette `Config` class. Note that
FastAPI updated the Starlette minor version from 0.36 to 0.37 in the
0.110.1 patch release.
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

Successfully merging this pull request may close these issues.

None yet

3 participants