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

on_delete should be required #1801

Open
FluckyGo opened this issue Dec 5, 2024 · 2 comments
Open

on_delete should be required #1801

FluckyGo opened this issue Dec 5, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@FluckyGo
Copy link

FluckyGo commented Dec 5, 2024

Is your feature request related to a problem? Please describe.
I encountered that when declaring ForeignKeyField on_delete = CASCADE, I believe that this is dangerous and in some scenarios may lead to undesirable consequences.

def ForeignKeyField(
    model_name: str,
    related_name: Union[Optional[str], Literal[False]] = None,
    on_delete: OnDelete = CASCADE,
    db_constraint: bool = True,
    null: bool = False,
    **kwargs: Any,
) -> "ForeignKeyRelation[MODEL] | ForeignKeyNullableRelation[MODEL]":

Describe the solution you'd like
The best solution would be to make on_delete a mandatory parameter, I believe that actions with data should be explicit.

def ForeignKeyField(
    model_name: str,
    on_delete: OnDelete,
    related_name: Union[Optional[str], Literal[False]] = None,
    db_constraint: bool = True,
    null: bool = False,
    **kwargs: Any,
) -> "ForeignKeyRelation[MODEL] | ForeignKeyNullableRelation[MODEL]":
@Abdeldjalil-H
Copy link
Contributor

I agree with you @FluckyGo. Using CASCADE as the default is dangerous. If it is not mandatory, it should be something like NO_ACTION.

What do you think @henadzit ?

@henadzit
Copy link
Contributor

henadzit commented Dec 8, 2024

I agree! It's mandatory in Django too. @abondar, your thoughts?

@henadzit henadzit added enhancement New feature or request good first issue Good for newcomers labels Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants