Skip to content

warn instead of raise for missing env file - #2485

Merged
Kludex merged 1 commit into
Kludex:masterfrom
mathause:warn_on_missing_env_file
Feb 6, 2024
Merged

Kludex merged 1 commit into
Kludex:masterfrom
mathause:warn_on_missing_env_file

Conversation

@mathause

@mathause mathause commented Feb 6, 2024

Copy link
Copy Markdown
Contributor

Summary

Adresses #2422

Let me know if you want a custom Warning and/ or any doc changes.

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.

@Kludex

Kludex commented Feb 6, 2024

Copy link
Copy Markdown
Owner

Thanks.

@Kludex
Kludex merged commit 7ec763c into Kludex:master Feb 6, 2024
@mathause
mathause deleted the warn_on_missing_env_file branch February 7, 2024 09:23
@mathause

mathause commented Feb 7, 2024

Copy link
Copy Markdown
Contributor Author

Thanks & sorry for the churn.

@tvasenin

tvasenin commented Feb 9, 2024

Copy link
Copy Markdown
Contributor

@Kludex Could you pls release the fixed version asap? (maybe even backport to 0.36.x releases, since it's used by latest FastsAPI v0.109.2)

@Kludex

Kludex commented Feb 9, 2024

Copy link
Copy Markdown
Owner

@tvasenin Can you open a PR analogous to this: #2457 with 0.37.1?

tvasenin added a commit to tvasenin/fastapi that referenced this pull request Mar 19, 2024
v0.36.0 to v0.37.0 had a regression failing on missing .env file.

Fixed in v0.37.1: Kludex/starlette#2485
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 (Kludex/starlette#2422, Kludex/starlette#2446).
In 0.37, the exception handling behavior has been changed again to raise
a warning instead of an exception (Kludex/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 (Kludex/starlette#2422, Kludex/starlette#2446).
In 0.37, the exception handling behavior has been changed again to raise
a warning instead of an exception (Kludex/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.

3 participants