Repository navigation
Stop python-dotenv warning about flexmeasures.cfg on startup - #2845
Merged
Merged
Conversation
…v file The config file is Python, so python-dotenv warned "could not parse statement" about any line that is not a plain assignment, such as an import on its first line. Since #2811 the Docker image finds its mounted config again, so every container logged this warning on startup. Now the file is parsed with ast, without running it, and only a top-level string literal counts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
Documentation build overview
9 files changed ·
|
Flix6x
commented
Nov 10, 2026
…e API The generate-openapi-specs hook stamped it with the development version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
… mark Parsing the decoded text kept the BOM, so the parse failed and the app silently ran in production; parsing the bytes honours a BOM and a coding declaration, as running the file does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
… let its last assignment win A cfg that cannot be read or parsed, or that sets FLEXMEASURES_ENV to an expression, used to fall back to the default environment silently. A later assignment of an expression now also undoes an earlier string literal, as it does when the file runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl> # Conflicts: # documentation/changelog.rst
Flix6x
added a commit
that referenced
this pull request
Nov 11, 2026
The v1.1.1 patch release backports #2855, #2861, #2838, #2829, #2851, #2845, #2859, #2850 and #2860 to the 1.1.x branch. Move their changelog bullets out of the v1.2.0 section into a new v1.1.1 section, worded and ordered as on 1.1.x, so the same fixes are not listed as unreleased once 1.1.1 ships. The bullet for #2861 takes the 1.1.x wording, which adds that Python 3.10 keeps the earlier Pillow, dnspython and filelock. The API change log needs no split: v3.0-35 holds only #2859, which ships in v1.1.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <felix@seita.nl>
Flix6x
added a commit
that referenced
this pull request
Nov 11, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <felix@seita.nl>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Since v1.1.0, every container of the Docker image logs
WARNING: python-dotenv could not parse statement starting at line 1on startup.get_flexmeasures_env()looked upFLEXMEASURES_ENVinflexmeasures.cfgwithdotenv_values(). That file is Python, so python-dotenv warns about any line that is not a plainKEY = valueassignment, such asfrom datetime import timedeltaon line 1. Spaces around=are fine for dotenv; imports and other statements are not./app/instance, so there was nothing to parse. Docker image: read the mounted config again, restore gunicorn's logs, and let pip install into the venv #2811 (in v1.1.0) fixed that.ast, without running it. Only a top-level string literal assigned toFLEXMEASURES_ENVcounts. The last top-level assignment wins, as it does when the file runs, so a later expression undoes an earlier literal. An expression is no longer mistaken for a string.FLEXMEASURES_ENVto something other than a string literal, now logs a warning instead of silently falling back to the default environment. A missing cfg stays silent.FLEXMEASURES_ENVenvironment variable is set and the app is not in testing mode.documentation/changelog.rstHow to test
pytest flexmeasures/utils/tests/test_config_utils.pytest_flexmeasures_env_from_a_python_cfg_raises_no_dotenv_warningfails onmainwith the very warning from the logs (dotenv.main, "python-dotenv could not parse statement starting at line %s"), and passes here.test_read_flexmeasures_env_from_cfgcovers plain and annotated assignments, last-one-wins (also when the last one is an expression), expressions, an absent setting, a file that is not Python, and a BOM with Windows line endings.test_read_flexmeasures_env_from_cfg_warns_when_it_cannot_telland..._does_not_warn_about_a_plain_cfgcover the warnings.Further Improvements
python-dotenv stays a dependency: the
flaskCLI uses it to read.flaskenv.This could go into a v1.1.1 patch release.
Related Items
Regression surfaced by #2811.
🤖 Generated with Claude Code