Raise an explicit error when MySQL config is missing instead of a silent SQLite fallback#10
Conversation
…ent SQLite fallback
|
Sorry about the failing checks, the tests were passing on my side. I have identified the issue: I see two options:
model_config = SettingsConfigDict(
case_sensitive=True,
env_file=(str(Path.home() / ".env.default"), ".env.example", ".env"),
extra="ignore",
)but we can maybe print a warning to say that it's using the default file but that a
Do you have a preference? |
|
I think option 1 with a warning is best: it allows to pass the tests without a .env while warning the user to create one. Option 2 is too error-prone in my opinion. What do you think? |
|
That's a good point. I agree, let's go with option 1 :) I'll push these changes. |
|
(Sorry, I'm mixing GitHub accounts 😅) So, in the end it took me down an unexpected rabbit hole... There is no (simple) way to check which environment file was used. Pydantic may use one file, or merge multiple files (i.e., you could have Even worse, if environment variables have been manually defined (e.g. I tried to find the sweet spot between all these weird possible combinations. Essentially, if only
I pushed these changes. Unit tests now pass, but they raise a warning since there is only [...]
tests/test_models_reference.py::TestCategoryToDict::test_all_fields_present PASSED [100%]
============================================================ warnings summary ============================================================
event_storage/settings.py:42
/home/joris/repositories/event-storage/event_storage/settings.py:42: RuntimeWarning: Only the example dotenv file (/home/joris/repositories/event-storage/.env.example) was found. If matching environment variables are set, they take precedence and .env.example may not affect the active configuration. To avoid ambiguity, create a real .env or ~/.env.default file, or remove .env.example.
warnings.warn(
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
===================================================== 181 passed, 1 warning in 1.49s =====================================================What do you think? |
|
Nice, seems perfect to me, thanks a lot! And good catch on removing the "thermal" in the example file 😅 |
Addresses issue #3.
When
DATABASE_URIis not provided andSQLITE=false, the settings code now requires all MySQL configuration values to be present instead of constructing an invalid URI with missing values. If any required MySQL setting is missing, a clear validation error is raised.