Skip to content

Commit ecb2613

Browse files
committed
fix: address code review findings (pass 1)
Claude-Session: https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4
1 parent f4daa4c commit ecb2613

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎modules/background_tasks/background_tasks/worker_settings.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ def settings_for[T: BaseSettings](
4141
with _lock:
4242
hit = _cache.get(key)
4343
if hit is not None and ttl > 0 and now - hit[0] < ttl:
44-
return cast(T, hit[1])
44+
# A copy: BaseSettings is mutable, so one task editing its settings
45+
# must not change what the next task in this process sees.
46+
return cast(T, hit[1]).model_copy(deep=True)
4547
with sync_session() as session:
4648
value = hydrate_settings_sync(cls, session, package)
4749
with _lock:
4850
_cache[key] = (now, value)
49-
return value
51+
return value.model_copy(deep=True)
5052

5153

5254
def clear_settings_cache() -> None:

‎modules/settings/settings/store.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def get_overrides_sync(session: Session, package: str) -> dict[str, tuple[str, s
6060
Setting.scope_id == SYSTEM_SCOPE_ID,
6161
Setting.key.startswith(f"{package}.", autoescape=True),
6262
)
63-
return package_overrides(((k, v, t) for k, v, t in session.execute(stmt)), package)
63+
return package_overrides(session.execute(stmt).tuples(), package)
6464

6565

6666
class SettingsStore:

0 commit comments

Comments
 (0)