Skip to content

Enforce cache key is a string - #8019

Open
Steve-Mcl wants to merge 2 commits into
mainfrom
7666-enforce-cache-key-string
Open

Enforce cache key is a string#8019
Steve-Mcl wants to merge 2 commits into
mainfrom
7666-enforce-cache-key-string

Conversation

@Steve-Mcl

Copy link
Copy Markdown
Contributor

Description

What does this PR do?

Makes the app's cache system reject non-string keys instead of silently misbehaving.

Why was this needed?

The app can store its short-lived cache data in one of two ways: an in-memory cache (used locally and in some environments) or a Redis/Valkey cache (used in production). These two behave differently if you accidentally use something other than a plain string as a cache key, e.g. a number instead of a string. The in-memory cache will quietly accept it and appear to work fine, but Redis handles keys differently and can fail in confusing ways.

This mismatch already caused a hard-to-track-down bug: something worked fine locally but broke in an environment using Redis, and it took a long time to figure out why, because the local setup didn't use Redis and couldn't have caught it.

What changed?

Both cache drivers now check that a key is a string before using it, and immediately throw a clear, descriptive error if it isn't. This means:

  • The same mistake now fails the same way everywhere, whether running locally or in production.
  • Problems like this get caught early, during development or testing, instead of surfacing later as a confusing production issue.

Testing

Added tests to confirm both cache drivers reject non-string keys consistently.

Related Issue(s)

closes #7666

Checklist

  • I have read the contribution guidelines
  • Suitable unit/system level tests have been added and they pass
  • Documentation has been updated
    • Upgrade instructions
    • Configuration details
    • Concepts
  • Changes flowforge.yml?
    • Issue/PR raised on FlowFuse/helm to update ConfigMap Template
    • Issue/PR raised on FlowFuse/CloudProject to update values for Staging/Production
  • Link to Changelog Entry PR, or note why one is not needed.

Labels

  • Includes a DB migration? -> add the area:migration label

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.14%. Comparing base (c2ae1d0) to head (65a222a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8019      +/-   ##
==========================================
+ Coverage   76.13%   76.14%   +0.01%     
==========================================
  Files         439      440       +1     
  Lines       23548    23560      +12     
  Branches     6272     6273       +1     
==========================================
+ Hits        17928    17940      +12     
  Misses       5620     5620              
Flag Coverage Δ
backend 76.14% <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 Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Enforce string keys on cache drivers

2 participants