Skip to content

Feat: soft deletion#15

Closed
Fushimi-Michaelis wants to merge 5 commits into
apache:masterfrom
Fushimi-Michaelis:master
Closed

Feat: soft deletion#15
Fushimi-Michaelis wants to merge 5 commits into
apache:masterfrom
Fushimi-Michaelis:master

Conversation

@Fushimi-Michaelis

@Fushimi-Michaelis Fushimi-Michaelis commented Oct 10, 2025

Copy link
Copy Markdown

Fix: #14

await self._save_policy_line(ptype, rule)

async def add_policies(self, sec, ptype, rules):
"""adds a policy rules to the storage."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why remove comments?

Comment thread casbin_async_sqlalchemy_adapter/adapter.py Outdated
return True if r.rowcount > 0 else False

async def remove_policies(self, sec, ptype, rules):
"""remove policy rules from the storage."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why remove comments?

Comment thread casbin_async_sqlalchemy_adapter/adapter.py Outdated
Comment thread casbin_async_sqlalchemy_adapter/adapter.py
@Fushimi-Michaelis

Copy link
Copy Markdown
Author

Feat: Soft delete is completed. Tests and README are updated. Missing comments have been restored.

@hsluoyz
hsluoyz requested a review from Copilot October 11, 2025 12:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines +195 to +196
print(lines_before_changes)

Copilot AI Oct 11, 2025

Copy link

Choose a reason for hiding this comment

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

Debug print statement should be removed from production code. This appears to be leftover debugging code that will pollute the output.

Suggested change
print(lines_before_changes)

Copilot uses AI. Check for mistakes.
return '<CasbinRule {}: "{}">'.format(self.id, str(self))


def query_for_rule(adaper, ptype, v0, v1, v2):

Copilot AI Oct 11, 2025

Copy link

Choose a reason for hiding this comment

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

Corrected spelling of 'adaper' to 'adapter'.

Copilot uses AI. Check for mistakes.
rule_filter.v2 = [v2]

stmt = select(CasbinRuleSoftDelete)
stmt = adaper.filter_query(stmt, rule_filter)

Copilot AI Oct 11, 2025

Copy link

Choose a reason for hiding this comment

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

Corrected spelling of 'adaper' to 'adapter'.

Copilot uses AI. Check for mistakes.
Comment on lines 143 to 146
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():

Copilot AI Oct 11, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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():

Copilot uses AI. Check for mistakes.
@Fushimi-Michaelis Fushimi-Michaelis closed this by deleting the head repository Nov 22, 2025
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.

Is there a plan to support soft deletion?

3 participants