Skip to content

Deep code review of SQL permissions system#2634

Open
simonw wants to merge 4 commits intomainfrom
claude/review-sql-permissions-8toT4
Open

Deep code review of SQL permissions system#2634
simonw wants to merge 4 commits intomainfrom
claude/review-sql-permissions-8toT4

Conversation

@simonw
Copy link
Copy Markdown
Owner

@simonw simonw commented Feb 6, 2026

Comprehensive analysis of the permission system introduced in 1.0a20
through 1.0a24, covering architecture, security, performance, and
design concerns across 12 identified issues with prioritized
recommendations.

https://claude.ai/code/session_013EkyroQKPhcjdMbpHc9g4X


📚 Documentation preview 📚: https://datasette--2634.org.readthedocs.build/en/2634/

Comprehensive analysis of the permission system introduced in 1.0a20
through 1.0a24, covering architecture, security, performance, and
design concerns across 12 identified issues with prioritized
recommendations.

https://claude.ai/code/session_013EkyroQKPhcjdMbpHc9g4X
Detailed design for extracting build_cascading_ctes(),
collect_permission_rules(), and build_restriction_filter() to
replace three separate implementations with one shared SQL builder.
Includes migration plan and handles the include_is_private
complication.

https://claude.ai/code/session_013EkyroQKPhcjdMbpHc9g4X
Three changes:

1. Rewrite test_utils_permissions.py to exercise production code paths
   (allowed_resources / allowed) instead of the test-only
   resolve_permissions_from_catalog function. Tests now register plugins
   via ds.pm.register and call the real Datasette methods.

2. Remove resolve_permissions_from_catalog, resolve_permissions_with_candidates,
   and build_rules_union from datasette/utils/permissions.py. These were
   only used by tests and implemented the cascading logic a third time,
   independently of the two production implementations.

3. Fix bug in gather_permission_sql_from_hooks where empty params dicts
   ({}) would cause framework-injected params (:actor_id, :actor, :action)
   to be silently lost. The expression `params = permission_sql.params or {}`
   creates a new dict when params is {} (falsy), so setdefault writes to a
   throwaway dict. Fixed by explicitly checking `is None`.

https://claude.ai/code/session_013EkyroQKPhcjdMbpHc9g4X
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.54%. Comparing base (5873578) to head (6a5086b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2634      +/-   ##
==========================================
+ Coverage   90.37%   90.54%   +0.16%     
==========================================
  Files          52       52              
  Lines        7983     7936      -47     
==========================================
- Hits         7215     7186      -29     
+ Misses        768      750      -18     

☔ View full report in Codecov by Sentry.
📢 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.

2 participants