Skip to content

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Aug 26, 2025

Description

Fixes #1537

Related resources

Checklist

  • I have opened this pull request against master
  • I have added or modified the tests when changing logic
  • I have followed the conventional commits guidelines to add meaningful information into the changelog
  • I have read the contribution guidelines and I have joined #workgroup-pr-review on
    Slack to find a “pr review buddy” who is going to review my pull request.

Summary by Sourcery

Fix TypeError in folder permission cache updates by ensuring the cache stores sets, updating function signatures and docstrings accordingly, and enhancing tests for isolation and overwrite behavior

Bug Fixes:

  • Prevent TypeError when updating folder permission cache by changing cache value types to sets

Enhancements:

  • Update get_folder_permission_cache and update_folder_permission_cache to use Set[int] type hints and corresponding return values

Tests:

  • Adjust permission cache tests to use sets for id_list, add a test for overwriting existing cache entries, and clear cache after each permission-related test for isolation

Copy link
Contributor

sourcery-ai bot commented Aug 26, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Standardize folder permission cache to use sets of IDs and adjust the test suite accordingly to fix TypeErrors during cache updates.

File-Level Changes

Change Details Files
Switch folder permission cache to store and return sets of folder IDs
  • Changed get_folder_permission_cache return type from dict to Set[int]
  • Updated update_folder_permission_cache signature to accept Set[int]
  • Replaced fallback logic to initialize perms from cache directly instead of using get_folder_permission_cache
filer/cache.py
Update and extend tests for set-based cache and isolate cache state
  • Replaced list literals with set literals in permission cache tests
  • Added test to verify cache overwrite behavior
  • Inserted cache.clear() calls in permission-related tests to ensure isolation
tests/test_permission_cache.py
tests/test_permissions.py

Assessment against linked issues

Issue Objective Addressed Explanation
#1537 Fix the TypeError: 'set' object does not support item assignment when updating the folder permission cache.
#1537 Ensure that update_folder_permission_cache and get_folder_permission_cache use consistent data types (set instead of list/dict) for cached permissions.
#1537 Add or update tests to verify that folder permission cache updates and overwrites work correctly without raising errors.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `filer/cache.py:32` </location>
<code_context>


-def get_folder_permission_cache(user: UserModel, permission: str) -> typing.Optional[dict]:
+def get_folder_permission_cache(user: UserModel, permission: str) -> typing.Optional[typing.Set[int]]:
     """
     Retrieves the cached folder permissions for a given user and permission.
</code_context>

<issue_to_address>
Return type may not match actual cached structure.

The cache currently stores a dict, not a set, so the return type should match. Update the annotation or refactor the cache for consistency.
</issue_to_address>

### Comment 2
<location> `filer/cache.py:89` </location>
<code_context>
+    id_list (set): The set of IDs to set as the new permissions.
     """
-    perms = get_folder_permission_cache(user, permission) or {}
+    perms = cache.get(get_folder_perm_cache_key(user, permission)) or {}
     perms[user.pk] = id_list
     cache.set(get_folder_perm_cache_key(user, permission), perms)
</code_context>

<issue_to_address>
Direct cache access bypasses get_folder_permission_cache logic.

Using cache.get directly may cause issues if get_folder_permission_cache is updated to include extra logic. Please use the getter for consistency, or clarify the reason for direct access.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    perms = cache.get(get_folder_perm_cache_key(user, permission)) or {}
=======
    perms = get_folder_permission_cache(user, permission) or {}
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@fsbraun
Copy link
Member Author

fsbraun commented Aug 26, 2025

@PeterW-LWL Thank you! I have replaced my PR by your more thorough change!

Can you check my single comment?

Ensure it is a set

Co-authored-by: Fabian Braun <fsbraun@gmx.de>
@PeterW-LWL
Copy link
Contributor

@fsbraun I have accepted your proposed change.

@fsbraun fsbraun merged commit 9df2d5c into django-cms:master Aug 27, 2025
44 checks passed
@PeterW-LWL PeterW-LWL deleted the 1537-folder-permission-cache-error branch August 27, 2025 13:05
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.

folder permission cache update sometimes raises TypeError: 'set' object does not support item assignment
2 participants