Feat: soft deletion#15
Conversation
| await self._save_policy_line(ptype, rule) | ||
|
|
||
| async def add_policies(self, sec, ptype, rules): | ||
| """adds a policy rules to the storage.""" |
| return True if r.rowcount > 0 else False | ||
|
|
||
| async def remove_policies(self, sec, ptype, rules): | ||
| """remove policy rules from the storage.""" |
|
Feat: Soft delete is completed. Tests and README are updated. Missing comments have been restored. |
There was a problem hiding this comment.
Pull Request Overview
This PR implements soft deletion functionality for the async SQLAlchemy adapter, allowing policies to be marked as deleted rather than permanently removed from the database. The implementation adds a new soft_delete parameter to the Adapter constructor that accepts a Boolean column attribute for tracking deletion status.
- Added soft delete support through a configurable Boolean column parameter
- Modified all policy removal operations to set deletion flags instead of hard deleting records
- Updated policy loading operations to filter out soft-deleted records
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| casbin_async_sqlalchemy_adapter/adapter.py | Core implementation of soft delete functionality with adapter modifications |
| tests/test_adapter_softdelete.py | Comprehensive test suite for soft delete behavior |
| tests/test_adapter.py | Minor updates to existing tests for compatibility |
| README.md | Documentation explaining soft delete usage and configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| print(lines_before_changes) | ||
|
|
There was a problem hiding this comment.
Debug print statement should be removed from production code. This appears to be leftover debugging code that will pollute the output.
| print(lines_before_changes) |
| return '<CasbinRule {}: "{}">'.format(self.id, str(self)) | ||
|
|
||
|
|
||
| def query_for_rule(adaper, ptype, v0, v1, v2): |
There was a problem hiding this comment.
Corrected spelling of 'adaper' to 'adapter'.
| rule_filter.v2 = [v2] | ||
|
|
||
| stmt = select(CasbinRuleSoftDelete) | ||
| stmt = adaper.filter_query(stmt, rule_filter) |
There was a problem hiding this comment.
Corrected spelling of 'adaper' to 'adapter'.
| lines = await session.execute(select(self._db_class)) | ||
| if self.softdelete_attribute: | ||
| lines = await session.execute(select(self._db_class).where(not_(self.softdelete_attribute))) | ||
| for line in lines.scalars(): |
There was a problem hiding this comment.
The lines variable is being overwritten but the first query result is never used. The soft delete check should be applied to the initial query instead of executing a second query.
| lines = await session.execute(select(self._db_class)) | |
| if self.softdelete_attribute: | |
| lines = await session.execute(select(self._db_class).where(not_(self.softdelete_attribute))) | |
| for line in lines.scalars(): | |
| stmt = select(self._db_class) | |
| if self.softdelete_attribute: | |
| stmt = stmt.where(not_(self.softdelete_attribute)) | |
| result = await session.execute(stmt) | |
| for line in result.scalars(): |
Fix: #14