Skip to content

feat: add clear_policy() method to Adapter#26

Merged
mserico merged 7 commits intomasterfrom
copilot/fix-clear-policy-functionality
Dec 10, 2025
Merged

feat: add clear_policy() method to Adapter#26
mserico merged 7 commits intomasterfrom
copilot/fix-clear-policy-functionality

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

fix: #25

@mserico mserico marked this pull request as ready for review December 10, 2025 14:12
Copilot AI and others added 4 commits December 10, 2025 14:21
Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix clear_policy() to clean casbin_rule table Add clear_policy() method to Adapter for direct database cleanup Dec 10, 2025
Copilot AI requested a review from mserico December 10, 2025 14:27
@mserico
Copy link

mserico commented Dec 10, 2025

@copilot fix linter check:

Run github/super-linter@v4.2.2
/usr/bin/docker run --name ghcriogithubsuperlinterv422_aebf9b --label a01628 --workdir /github/workspace --rm -e "VALIDATE_PYTHON_BLACK" -e "DEFAULT_BRANCH" -e "GITHUB_TOKEN" -e "LINTER_RULES_PATH" -e "PYTHON_BLACK_CONFIG_FILE" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_ENVIRONMENT" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e "ACTIONS_RESULTS_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp":"/github/runner_temp" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/async-sqlalchemy-adapter/async-sqlalchemy-adapter":"/github/workspace" ghcr.io/github/super-linter:v4.2.2
--------------------------------------------------------------------------------

                              /@@#///////@@/(@//@%/(@.@(       @@
                          @@//////////////////////////////#*  @@@
                        @////@//(///////////@@@@@///@//@/@**//@@(
                      @///////@///////////////@@@@    (           @,
                     @/(&/@////////////////////                     @
                    @////////////////////////@@                      @
                  @%////////(//////////%/////&@            @@       *,@           ______________
             @@@@@/@/#/////(&//////////////////                       .@         /              \
        *@@@@@.    .%///(//@//////////////////&.   .@@,                 @%      / Don't mind me  \
      @@%           .&@&&/@.@//&/////(//////////    @@@@@@@@@         .. &@    / I'm just looking \
    @@%               @@@@@   @&/////////////////#   @/       V  @@/ ,@@@ @   <  for some trash... |
@@@%                   @@@@        .%@@@@//////#@ @   @@         @     .,.     \__________________/
                                          @@@/@(  (@@@@% @/\      %
                                           @@@@(    .     .@@/\   #
                                             @                  %@%

--------------------------------------------------------------------------------
2025-12-10 14:31:38 [INFO]   ---------------------------------------------
2025-12-10 14:31:38 [INFO]   --- GitHub Actions Multi Language Linter ----
2025-12-10 14:31:38 [INFO]    - Image Creation Date:[2021-06-10T18:15:15Z]
2025-12-10 14:31:38 [INFO]    - Image Revision:[c4280ea4e19a1d73ba41dbf44ea5de0b0dc165ce]
2025-12-10 14:31:38 [INFO]    - Image Version:[c4280ea4e19a1d73ba41dbf44ea5de0b0dc165ce]
2025-12-10 14:31:38 [INFO]   ---------------------------------------------
2025-12-10 14:31:38 [INFO]   ---------------------------------------------
2025-12-10 14:31:38 [INFO]   The Super-Linter source code can be found at:
2025-12-10 14:31:38 [INFO]    - https://github.com/github/super-linter
2025-12-10 14:31:38 [INFO]   ---------------------------------------------
2025-12-10 14:31:38 [INFO]   --------------------------------------------
2025-12-10 14:31:38 [INFO]   Gathering GitHub information...
2025-12-10 14:31:38 [INFO]   Successfully found:[GITHUB_SHA], value:[3d7fb895b61b216a583758221d28e17ae29a6da6]
2025-12-10 14:31:38 [INFO]   Successfully found:[GITHUB_WORKSPACE], value:[/github/workspace]
2025-12-10 14:31:38 [INFO]   Successfully found:[GITHUB_EVENT_PATH], value:[/github/workflow/event.json]
2025-12-10 14:31:38 [INFO]   Successfully found:[GITHUB_ORG], value:[officialpycasbin]
2025-12-10 14:31:38 [INFO]   Successfully found:[GITHUB_REPO], value:[async-sqlalchemy-adapter]
2025-12-10 14:31:38 [INFO]   Successfully found:[GITHUB_TOKEN]
2025-12-10 14:31:38 [INFO]   Successfully found:[GITHUB_REPOSITORY], value:[officialpycasbin/async-sqlalchemy-adapter]
2025-12-10 14:31:38 [INFO]   Successfully found:[GITHUB_RUN_ID], value:[20101966042]
2025-12-10 14:31:38 [INFO]   --------------------------------------------
2025-12-10 14:31:38 [INFO]   Gathering user validation information...
2025-12-10 14:31:38 [INFO]   - Validating ALL files in code base...
2025-12-10 14:31:39 [INFO]   ----------------------------------------------
2025-12-10 14:31:40 [INFO]   User provided file:[/github/workspace/pyproject.toml] exists, setting rules file...
2025-12-10 14:31:41 [INFO]   ---------------------------------
2025-12-10 14:31:41 [INFO]   ------ File list to check: ------
2025-12-10 14:31:41 [INFO]   ---------------------------------
2025-12-10 14:31:42 [INFO]   ----------------------------------------------
2025-12-10 14:31:42 [INFO]   Successfully gathered list of files...
2025-12-10 14:31:42 [INFO]   
2025-12-10 14:31:42 [INFO]   ----------------------------------------------
2025-12-10 14:31:42 [INFO]   ----------------------------------------------
2025-12-10 14:31:42 [INFO]   Linting [PYTHON_BLACK] files...
2025-12-10 14:31:42 [INFO]   ----------------------------------------------
2025-12-10 14:31:42 [INFO]   ----------------------------------------------
2025-12-10 14:31:42 [INFO]   ---------------------------
2025-12-10 14:31:42 [INFO]   File:[/github/workspace/casbin_async_sqlalchemy_adapter/__init__.py]
2025-12-10 14:31:42 [INFO]    - File:[__init__.py] was linted with [black] successfully
2025-12-10 14:31:42 [INFO]   ---------------------------
2025-12-10 14:31:42 [INFO]   File:[/github/workspace/casbin_async_sqlalchemy_adapter/adapter.py]
2025-12-10 14:31:43 [ERROR]   Found errors in [black] linter!
2025-12-10 14:31:43 [ERROR]   Error code: 1. Command output:
------
would reformat /github/workspace/casbin_async_sqlalchemy_adapter/adapter.py
Oh no! 💥 💔 💥
1 file would be reformatted.
--- /github/workspace/casbin_async_sqlalchemy_adapter/adapter.py	2025-12-10 14:31:37.715415 +0000
+++ /github/workspace/casbin_async_sqlalchemy_adapter/adapter.py	2025-12-10 14:31:43.336920 +0000
@@ -268,14 +268,14 @@
 
         return True
 
     async def clear_policy(self):
         """Clears all policy rules from the storage (database).
-        
+
         This method removes all records from the casbin_rule table.
         If soft delete is enabled, it marks all records as deleted.
-        
+
         Returns:
             bool: True if successful, False otherwise.
         """
         async with self._session_scope() as session:
             if self.softdelete_attribute is None:
------
2025-12-10 14:31:43 [INFO]   ---------------------------
2025-12-10 14:31:43 [INFO]   File:[/github/workspace/tests/test_adapter.py]
2025-12-10 14:31:43 [INFO]    - File:[test_adapter.py] was linted with [black] successfully
2025-12-10 14:31:43 [INFO]   ---------------------------
2025-12-10 14:31:43 [INFO]   File:[/github/workspace/tests/test_adapter_softdelete.py]
2025-12-10 14:31:44 [INFO]    - File:[test_adapter_softdelete.py] was linted with [black] successfully
2025-12-10 14:31:44 [INFO]   ---------------------------
2025-12-10 14:31:44 [INFO]   File:[/github/workspace/tests/test_external_session.py]
2025-12-10 14:31:44 [INFO]    - File:[test_external_session.py] was linted with [black] successfully
2025-12-10 14:31:44 [INFO]   ----------------------------------------------
2025-12-10 14:31:44 [INFO]   ----------------------------------------------
2025-12-10 14:31:44 [INFO]   The script has completed
2025-12-10 14:31:44 [INFO]   ----------------------------------------------
2025-12-10 14:31:44 [INFO]   ----------------------------------------------
2025-12-10 14:31:44 [ERROR]   ERRORS FOUND in PYTHON_BLACK:[1]
2025-12-10 14:31:44 [FATAL]   Exiting with errors found!

Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 10, 2025

@copilot fix linter check:

...

Fixed in 8fa57a8 - removed trailing whitespace from the docstring that was causing the Black linter failure.

@mserico
Copy link

mserico commented Dec 10, 2025

@copilot add the new clear_policy() API to README, only adding one test case is enough

Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 10, 2025

@copilot add the new clear_policy() API to README, only adding one test case is enough

Added in adf8405 - included a "Clearing All Policies" section in the README with a concise example showing how to use clear_policy() for both setup and clearing. Also noted the behavior difference when soft deletion is enabled.

@mserico mserico changed the title Add clear_policy() method to Adapter for direct database cleanup feat: add clear_policy() method to Adapter Dec 10, 2025
@mserico mserico merged commit cb0a4bb into master Dec 10, 2025
13 checks passed
github-actions bot pushed a commit that referenced this pull request Dec 10, 2025
# [1.17.0](v1.16.1...v1.17.0) (2025-12-10)

### Features

* add clear_policy() method to Adapter ([#26](#26)) ([a989130](a989130))
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.

clear_policy() doesn't clean casbin_rule table

2 participants