tortoise / tortoise/tortoise-orm
on_delete=CASCADE doesn't fire pre_delete and post_delete signals
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
tortoise-orm==0.19.3
Setup
class FileBaseModel(models.Model):
host = fields.ForeignKeyField(
"models.Equipment", related_name="files", on_delete=fields.CASCADE, null=True
)
@pre_delete(FileBaseModel)
async def equipment_media_pre_delete(
sender: Type[FileBaseModel],
file: FileBaseModel,
using_db: Optional[BaseDBAsyncClient],
) -> None:
log.info(f"pre_delete signal for file {file}")
Code
equipment = await Equipment.create(...)
file = await FileBaseModel.create(host=equipment)
await file.delete()
#### INFO: pre_delete signal for file <FileBaseModel>
file = await FileBaseModel.create(host=equipment)
await equipment.delete()
#### Nothing happens! No logs...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the shown FileBaseModel and Equipment setup, comparing file.delete() with equipment.delete(). Trace the deletion cascade and signal dispatch from those delete entry points. Done means cascading deletion invokes both pre_delete and post_delete for the related FileBaseModel, with regression coverage for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100