Skip to content

fix: Clear config cache after integration env var injection#92

Merged
mfranczel merged 4 commits intomainfrom
michal/blu-5912-clear-config-cache-after-integration-env-var-injection
Apr 10, 2026
Merged

fix: Clear config cache after integration env var injection#92
mfranczel merged 4 commits intomainfrom
michal/blu-5912-clear-config-cache-after-integration-env-var-injection

Conversation

@mfranczel
Copy link
Copy Markdown
Contributor

@mfranczel mfranczel commented Apr 9, 2026

Problem

get_config() is memoized via @lru_cache. During runtime init, it gets called (and cached) before set_integration_env() fetches and injects integration env vars like DEEPNOTE_DO_NOT_COERCE_FLOAT. The cached config never sees the late-arriving variable.

Fix

Call clear_config_cache() at the end of set_integration_env() after env vars are written, so the next get_config() re-reads the environment

Summary by CodeRabbit

  • Bug Fixes

    • Integration-provided environment variables now trigger a refresh so configuration changes take effect immediately.
  • Tests

    • Added unit tests to ensure the config cache is cleared when integrations set env vars and that runtime settings update accordingly.

@linear
Copy link
Copy Markdown

linear bot commented Apr 9, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

📝 Walkthrough

Walkthrough

set_integration_env() was updated to call clear_config_cache() after applying environment variables fetched from integrations so that subsequent get_config() reads updated values. Tests were added: one verifies that clearing the config cache lets a late-set env var affect get_config(), and another asserts set_integration_env() calls clear_config_cache() once when integrations provide variables.

Sequence Diagram(s)

sequenceDiagram
    participant Script as set_integration_env()
    participant HTTP as Integration API
    participant Env as OS Environment
    participant Config as config.get_config / cache

    Script->>HTTP: fetch integration vars
    HTTP-->>Script: returns vars (e.g. DEEPNOTE_DO_NOT_COERCE_FLOAT)
    Script->>Env: set environment variables
    Script->>Config: clear_config_cache()
    Note right of Config: next get_config() will re-read env
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Updates Docs ❓ Inconclusive PR is a bug fix with no documentation file changes; check requires documentation for features, unclear if applies to bug fixes. Confirm if internal documentation was updated or document decision that no external docs needed for this caching implementation detail.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title accurately describes the main change: clearing config cache after integration environment variable injection to fix memoization issues.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

📦 Python package built successfully!

  • Version: 2.2.0.dev9+7d43f54
  • Wheel: deepnote_toolkit-2.2.0.dev9+7d43f54-py3-none-any.whl
  • Install:
    pip install "deepnote-toolkit @ https://deepnote-staging-runtime-artifactory.s3.amazonaws.com/deepnote-toolkit-packages/2.2.0.dev9%2B7d43f54/deepnote_toolkit-2.2.0.dev9%2B7d43f54-py3-none-any.whl"

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.32%. Comparing base (1d5be74) to head (ed1621b).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #92   +/-   ##
=======================================
  Coverage   74.32%   74.32%           
=======================================
  Files          94       94           
  Lines        5534     5535    +1     
  Branches      824      824           
=======================================
+ Hits         4113     4114    +1     
  Misses       1155     1155           
  Partials      266      266           
Flag Coverage Δ
combined 74.32% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/test_config.py`:
- Line 30: Add an explicit return type annotation to the test function signature
for test_coerce_float_picks_up_late_env_after_cache_clear by changing its def
line to include "-> None"; update the function definition of
test_coerce_float_picks_up_late_env_after_cache_clear to declare a None return
type to comply with the project's type-hinting guideline.

In `@tests/unit/test_set_integrations_env.py`:
- Around line 102-107: Replace the loose invocation check in the test so it
asserts exactly one call: in the block that patches
"deepnote_toolkit.set_integrations_env.clear_config_cache" and invokes
set_integration_env(), change the assertion from using mock_clear.called to
calling mock_clear.assert_called_once() to ensure the cache-clear function was
invoked exactly once.
- Around line 81-95: Update the new test function and its nested dummy classes
to include explicit type hints: annotate the test function parameters
(mock_get_config, monkeypatch) with their expected types, add return type
annotations for DummyResp.json (-> list[dict[str, str]] or appropriate type) and
for DummySession.get (-> DummyResp) and DummySession.mount (-> None), and
annotate any method arguments (e.g., *a: Any, **k: Any) so all functions and
methods in test_set_integration_env_clears_config_cache, DummyResp.json,
DummySession.mount, and DummySession.get have explicit parameter and return type
hints.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d96bd3e9-4e88-47bb-8506-d581016bd0eb

📥 Commits

Reviewing files that changed from the base of the PR and between 1d5be74 and 7c586a3.

📒 Files selected for processing (3)
  • deepnote_toolkit/set_integrations_env.py
  • tests/unit/test_config.py
  • tests/unit/test_set_integrations_env.py

@deepnote-bot
Copy link
Copy Markdown

deepnote-bot commented Apr 9, 2026

🚀 Review App Deployment Started

📝 Description 🌐 Link / Info
🌍 Review application ra-92
🔑 Sign-in URL Click to sign-in
📊 Application logs View logs
🔄 Actions Click to redeploy
🚀 ArgoCD deployment View deployment
Last deployed 2026-04-10 13:51:51 (UTC)
📜 Deployed commit e1d78f8eda075369bee688f7585fa84a517a269a
🛠️ Toolkit version 7d43f54

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
tests/unit/test_set_integrations_env.py (1)

81-95: ⚠️ Potential issue | 🟡 Minor

Add explicit type hints in the new test segment.

Line 81, Line 87, Line 91, and Line 94 are still missing annotations in the new test and nested dummy methods.

Proposed fix
+from typing import Any
 import types
 from unittest import mock
@@
 def test_set_integration_env_clears_config_cache(
-    mock_get_config, monkeypatch  # noqa: ARG001
-):
+    mock_get_config: mock.MagicMock, monkeypatch: pytest.MonkeyPatch  # noqa: ARG001
+) -> None:
     class DummyResp:
         ok = True
 
-        def json(self):
+        def json(self) -> list[dict[str, str]]:
             return [{"name": "DEEPNOTE_DO_NOT_COERCE_FLOAT", "value": "1"}]
 
     class DummySession:
-        def mount(self, *a, **k):
+        def mount(self, *a: Any, **k: Any) -> None:
             pass
 
-        def get(self, *a, **k):
+        def get(self, *a: Any, **k: Any) -> DummyResp:
             return DummyResp()
#!/bin/bash
ruff check tests/unit/test_set_integrations_env.py --select ANN,ARG

As per coding guidelines, "Use explicit type hints for function parameters and return values".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/test_set_integrations_env.py` around lines 81 - 95, Add explicit
type annotations to the new test and its nested dummy classes: annotate the test
function parameters in test_set_integration_env_clears_config_cache
(mock_get_config, monkeypatch) with appropriate types (e.g., fixtures' types or
typing.Any), add a return type for DummyResp.json (-> list[dict] or -> Any) and
for DummySession.mount and DummySession.get (-> None and -> DummyResp or -> Any
respectively). Ensure imports from typing are added if needed and use the exact
symbol names DummyResp.json, DummySession.mount, DummySession.get, and
test_set_integration_env_clears_config_cache to locate where to add the
annotations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/test_set_integrations_env.py`:
- Around line 100-107: This test can leak the DEEPNOTE_DO_NOT_COERCE_FLOAT
environment variable set by set_integration_env(); before calling
set_integration_env() in the test (which currently uses monkeypatch and mocks
clear_config_cache), capture the original value of DEEPNOTE_DO_NOT_COERCE_FLOAT
(e.g., via os.environ.get or monkeypatch) and after the assertion restore it to
its prior state (use monkeypatch.setenv or monkeypatch.delenv as appropriate) so
the environment is unchanged for subsequent tests; keep references to
set_integration_env and the existing mock_clear.assert_called_once() intact.

---

Duplicate comments:
In `@tests/unit/test_set_integrations_env.py`:
- Around line 81-95: Add explicit type annotations to the new test and its
nested dummy classes: annotate the test function parameters in
test_set_integration_env_clears_config_cache (mock_get_config, monkeypatch) with
appropriate types (e.g., fixtures' types or typing.Any), add a return type for
DummyResp.json (-> list[dict] or -> Any) and for DummySession.mount and
DummySession.get (-> None and -> DummyResp or -> Any respectively). Ensure
imports from typing are added if needed and use the exact symbol names
DummyResp.json, DummySession.mount, DummySession.get, and
test_set_integration_env_clears_config_cache to locate where to add the
annotations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0a30774d-53e6-4cb6-8308-8d637b974845

📥 Commits

Reviewing files that changed from the base of the PR and between 7c586a3 and 96d15d1.

📒 Files selected for processing (1)
  • tests/unit/test_set_integrations_env.py

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 9, 2026
@mfranczel mfranczel requested a review from m1so April 9, 2026 15:06
@mfranczel mfranczel marked this pull request as ready for review April 9, 2026 15:06
@mfranczel mfranczel requested a review from a team as a code owner April 9, 2026 15:06
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
tests/unit/test_config.py (1)

30-30: 🛠️ Refactor suggestion | 🟠 Major

Add explicit type hints to the test signature.

Please type the fixture and return explicitly, e.g. monkeypatch: pytest.MonkeyPatch and -> None.

Proposed fix
-def test_coerce_float_picks_up_late_env_after_cache_clear(monkeypatch):
+def test_coerce_float_picks_up_late_env_after_cache_clear(
+    monkeypatch: pytest.MonkeyPatch,
+) -> None:

As per coding guidelines, "Use explicit type hints for function parameters and return values".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/test_config.py` at line 30, The test function
test_coerce_float_picks_up_late_env_after_cache_clear is missing explicit type
hints on its signature; update the parameter and return types to follow
guidelines by annotating monkeypatch as pytest.MonkeyPatch and the function
return as -> None (e.g., monkeypatch: pytest.MonkeyPatch and -> None) so the
test signature is explicitly typed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@tests/unit/test_config.py`:
- Line 30: The test function
test_coerce_float_picks_up_late_env_after_cache_clear is missing explicit type
hints on its signature; update the parameter and return types to follow
guidelines by annotating monkeypatch as pytest.MonkeyPatch and the function
return as -> None (e.g., monkeypatch: pytest.MonkeyPatch and -> None) so the
test signature is explicitly typed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d7c6708a-7e3f-4e40-969a-927995e861c8

📥 Commits

Reviewing files that changed from the base of the PR and between 96d15d1 and b2b9227.

📒 Files selected for processing (1)
  • tests/unit/test_config.py

@mfranczel mfranczel merged commit 7ca9716 into main Apr 10, 2026
32 checks passed
@mfranczel mfranczel deleted the michal/blu-5912-clear-config-cache-after-integration-env-var-injection branch April 10, 2026 13:50
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