Issue #956: Disable SQLAlchemy echo in MDR API (env-driven) - #1147
Issue #956: Disable SQLAlchemy echo in MDR API (env-driven)#1147dereck-symmetry wants to merge 5 commits into
Conversation
bjagg
left a comment
There was a problem hiding this comment.
Overview
Makes SQLAlchemy echo env-driven and defaults it off, fixing #956. This is the most complete of the three PRs currently open from this branch series — the change itself is two lines, and the rest is the follow-through that usually gets skipped:
deployments/advisor-demo-docker/docker-compose.yml— wired with afalsedefaultprojects/lif_mdr_api/mdr-api.env.example— documented with a "keep false" noteprojects/lif_mdr_api/README.md— added to the env-var tabletest/bases/lif/mdr_restapi/conftest.py— the test engine's hardcodedecho=Truepicked up too, which is easy to miss- New tests for default-off, on-for-
true, and off-for-anything-else
The inline comment explaining why (echo emits every statement plus bound parameters at INFO) is the right thing to leave behind. Deliberately not adding SQLALCHEMY_ECHO to the CloudFormation task definitions is also correct — absent means false, which is the desired deployed behavior.
One required change: importlib.reload() in tests
test/components/lif/mdr_utils/test_database_setup.py — the new TestEchoToggle class reloads the module under each env condition:
return importlib.reload(database_setup).engine.echoCLAUDE.md:125 prohibits this directly:
Avoid
importlib.reload()in tests — it breaksisinstance()/pytest.raises()matching. Usemock.patch.object(module, "VAR_NAME", value)instead.
git grep importlib.reload -- test/ returns nothing on main, so this would introduce the only use in the suite. Beyond the convention, reloading database_setup rebinds module-level engine and async_session for every test that imports them afterward, which makes suite behavior order-dependent — the class docstring acknowledges the engine is built at import time, which is exactly the hazard.
The underlying difficulty is real: engine is constructed at module import, so there's no seam to patch. Two ways out:
- Test the predicate rather than the engine — extract the parse (
os.getenv("SQLALCHEMY_ECHO", "false").lower() == "true") into a small function and test that directly. It's the only logic here;create_async_enginefaithfully storingechois framework behavior. - Or
mock.patch.object(database_setup, "SQLALCHEMY_ECHO", True)per the convention, if what's being asserted is downstream use of the flag.
Option 1 is probably the better shape — it also gives the flag a name that can be reused if another engine needs it.
Minor
cspell.jsonaddsSQLALCHEMY— fine, thoughsqlalchemymay already be present in a different case; worth a quick check to avoid a duplicate entry.- Consider whether
MDR__prefixing would be more consistent with the surrounding settings (MDR__AUTH__*,MDR__COOKIE__*).SQLALCHEMY_ECHOis unprefixed likePOSTGRESQL_*, so either convention has precedent — just worth a deliberate choice rather than an accident.
Verdict
Approve once the importlib.reload() test is reworked. Everything else here is ready, and the completeness of the non-code follow-through is worth calling out — the conftest.py catch in particular.
Note this PR is currently BEHIND main; it'll need a branch update before merge.
.claude/plans/772-import-transformation-groups.md is agent-planning scratch space that was inadvertently committed during the #772 work (#1136/#1143) — plan docs are working notes, not repo artifacts. This removes it from version control to correct that mistake, and ignores .claude/plans/ so it cannot recur. Also adds ntvs/njsproj (pre-existing VS IDE entries in .gitignore) to the cspell dictionary, which surfaced when .gitignore entered hook scope.
|
Thanks @bjagg — all points addressed:
One extra commit flagged for transparency: 3d9457c removes Re-requesting quick review per repo rules. |
…e. This change makes no change to other files
Include:
Related Issues
Closes #956
Type of Change
to not work as expected)
Project Area(s) Affected
Checklist
uv run ruff check)uv run ruff format)uv run ty check)Testing
Additional Notes
Configuration updates done with the help of LLM. Did a complete deploy locally with docker to assure that the data was working.