Source: https://reporules.fyi/django/

# Django: Perch rule pack

3 saved requirements for Django. Inspect the selectors and adapt the example paths to your repository.

```
- name: tenant-scoped-lock
  where: "orders/cancellation.py"
  ensure: >-
    Before mutating an order, the locked queryset must filter tenant_id by actor.tenant_id. Matching owner_id without the tenant restriction is insufficient.

- name: outbox-same-atomic-block
  where: "orders/confirmation.py"
  ensure: >-
    OutboxEvent.objects.create must run inside the same transaction.atomic block as order.save. Moving event insertion after the atomic block breaks the rule.

- name: notify-after-commit
  where: "orders/services.py"
  ensure: >-
    Order notification callbacks are registered with transaction.on_commit inside the atomic block, so a rolled-back order update does not send a notification.
```

[Download the rule pack ZIP](https://reporules.fyi/django/rule-pack.zip) · [Download YAML](https://reporules.fyi/django/rules.yaml) · [Agent repair task](https://reporules.fyi/django/agent-task.txt) · [Implementation, integration requirements and captured checks](https://frameworkrecipes.dev/django/)

## Install the rule without replacing your configuration

```
npm install -g @lakeday/perch
perch login
curl -fL 'https://reporules.fyi/django/rule-pack.zip' -o 'perch-guide-django.zip'
unzip -n 'perch-guide-django.zip'
```

Keep your existing perch.yaml. Extraction preserves existing files and adds .perch/rules/perch-guide-django.yaml. Review each where selector before running a check on your application.

## Configure your coding agent

```
perch setup claude-code
perch setup codex
perch setup cursor
perch setup pi
```

Choose the setup command for the agent you use.

## Check the edit, fix the finding, check again

```
perch check orders/cancellation.py --rules tenant-scoped-lock --json
perch check orders/confirmation.py --rules outbox-same-atomic-block --json
perch check orders/services.py --rules notify-after-commit --json
```

Run the check after an agent edit. Read the finding and affected code, repair the implementation, and repeat the identical command. Keep the application regression tests as separate gates.

Exit 3 means a finding. Exit 1 or 2 means the check did not complete. A pass does not prove application correctness. Fresh judgments can vary; unchanged requests reuse cached answers. Relevant source is sent to the configured model service.

[Pack manifest and SHA-256 hash](https://reporules.fyi/django/rule-pack.json) · [Pack README](https://reporules.fyi/django/rule-pack-readme.md)

**Repo Rules**

Requirements that stay in the repo.

Published by Perch · © 2026 Verglas LLC. Repo Rules is a Perch publication.

Perch’s MIT license covers the CLI; hosted model analysis is a paid service. Relevant source is sent to the configured model service.

[Perch CLI MIT license](https://github.com/lakeday-org/perch/blob/main/LICENSE) · [Article text](https://reporules.fyi/django/index.md) · [Resource index](https://reporules.fyi/llms.txt)
