Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against indefinite caching #1554

Merged
merged 1 commit into from
Jan 16, 2025
Merged

Conversation

swrichards
Copy link
Collaborator

Because the timeout value for the ZGW caching is taken from the Django settings, it is not unthinkable that, due to some misconfiguration, the timeout value could end up being None. If this is passed as-is to the low-level Django caching backend, it will be interpreted as "cache forever", because the default kwarg of 60 would be overridden. This can lead to unexpected behavior, e.g. ZGW API objects appearing to be stale because the cache never expires.

This commit makes this process more explicit by setting a default only if no timeout kwarg is provided, and also interpreting a timeout of "None" as a request for the default timeout, to fully prohibit "cache forever" scenarios.

@codecov-commenter
Copy link

codecov-commenter commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.

Project coverage is 94.23%. Comparing base (65b1058) to head (da16897).
Report is 6 commits behind head on develop.

Files with missing lines Patch % Lines
src/open_inwoner/utils/tests/test_utils.py 87.50% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1554      +/-   ##
===========================================
- Coverage    94.23%   94.23%   -0.01%     
===========================================
  Files         1068     1068              
  Lines        39348    39403      +55     
===========================================
+ Hits         37080    37131      +51     
- Misses        2268     2272       +4     

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

@swrichards swrichards marked this pull request as ready for review January 15, 2025 10:40
@swrichards swrichards requested a review from pi-sigma January 15, 2025 10:40
@swrichards swrichards force-pushed the guard-against-infinite-cache branch from b59b1ac to 7f06f88 Compare January 16, 2025 11:12
Because the timeout value for the ZGW caching is taken from the
Django settings, it is not unthinkable that, due to some
misconfiguration, the timeout value could end up being None. If
this is passed as-is to the low-level Django caching backend, it
will be interpreted as "cache forever", because the default kwarg
of 60 would be overridden. This can lead to unexpected behavior,
e.g. ZGW API objects appearing to be stale because the cache
never expires.

This commit makes sure an exception is raised if a non-integer
value is provided.
@swrichards swrichards force-pushed the guard-against-infinite-cache branch from 7f06f88 to da16897 Compare January 16, 2025 11:12
@swrichards swrichards requested a review from pi-sigma January 16, 2025 11:51
@alextreme alextreme merged commit ccc2b8f into develop Jan 16, 2025
21 checks passed
@alextreme alextreme deleted the guard-against-infinite-cache branch January 16, 2025 14:10
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.

4 participants