Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cascade Role Invitations delete while deleting project #17819

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Daksh2000
Copy link
Contributor

@Daksh2000 Daksh2000 commented Mar 19, 2025

Fixes: #17751

@Daksh2000 Daksh2000 requested a review from a team as a code owner March 19, 2025 18:44
@Daksh2000 Daksh2000 marked this pull request as draft March 19, 2025 19:08
@Daksh2000 Daksh2000 marked this pull request as ready for review March 19, 2025 19:31
Comment on lines 2187 to 2192
# Delete all role invitations for this project
(
request.db.query(RoleInvitation)
.filter(RoleInvitation.project == project)
.delete()
)
Copy link
Member

Choose a reason for hiding this comment

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

I think this should probably be done with an ondelete="CASCADE", similar to #3182.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @di , thank you for providing the reference, I tried adding cascade to "invitations" in Project Model and I was able to delete the projects with pending role_invitations
Although I did create alembic migrations as was the approach in previous issues, but I am not sure if they are needed here
PS - Below is my migration file (Not include in PR)


# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Add cascade delete to RoleInvitation

Revision ID: a39f43699c08
Revises: 6de76386dbf4
Create Date: 2025-03-20 23:16:20.429394

"""

from alembic import op


# revision identifiers, used by Alembic.
revision = "a39f43699c08"
down_revision = "6de76386dbf4"


def upgrade() -> None:
    """Upgrade schema: Add cascade delete to RoleInvitation.project_id at DB level"""
    op.execute(
        "ALTER TABLE role_invitations "
        "DROP CONSTRAINT IF EXISTS role_invitations_project_id_fkey"
    )
    op.create_foreign_key(
        "role_invitations_project_id_fkey",
        "role_invitations",
        "projects",
        ["project_id"],
        ["id"],
        ondelete="CASCADE"  # Enforcing CASCADE at the DB level
    )


def downgrade() -> None:
    """Downgrade schema: Remove cascade delete from RoleInvitation.project_id"""
    op.drop_constraint("role_invitations_project_id_fkey", "role_invitations", type_="foreignkey")
    op.create_foreign_key(
        "role_invitations_project_id_fkey",
        "role_invitations",
        "projects",
        ["project_id"],
        ["id"]
    )

@Daksh2000 Daksh2000 marked this pull request as draft March 20, 2025 20:01
@Daksh2000 Daksh2000 marked this pull request as ready for review March 21, 2025 17:29
@Daksh2000 Daksh2000 marked this pull request as draft March 21, 2025 17:31
@Daksh2000 Daksh2000 marked this pull request as ready for review March 21, 2025 17:59
@Daksh2000 Daksh2000 changed the title Deleting Role Invitations while deleting project Cascade Role Invitations delete while deleting project Mar 21, 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.

Getting "outage" error when deleting a project, but there is no outage happening.
3 participants