| 1 |
# Contributing to `django-guardian` |
| 2 |
|
| 3 |
Thank you for contributing to `django-guardian`. |
| 4 |
|
| 5 |
This project sits in the authorization and object-permission layer of Django applications, so correctness, backwards compatibility, and security matter as much as feature delivery. This document is the canonical contributor guide for the repository. Supporting docs under `docs/develop/` may explain individual tools in more detail, but maintainers review contributions against the standards in this file. |
| 6 |
|
| 7 |
## Before you start work |
| 8 |
|
| 9 |
### File an issue first |
| 10 |
|
| 11 |
For bug reports, feature requests, behavioral changes, or larger refactors, start by opening an issue in the repository: |
| 12 |
|
| 13 |
- <https://github.com/django-guardian/django-guardian/issues> |
| 14 |
|
| 15 |
This helps confirm that the proposal fits the project roadmap before significant implementation work begins. PRs that arrive without prior context may be closed if they are out of scope, too risky, or difficult to support long-term. |
| 16 |
|
| 17 |
### Do not report vulnerabilities publicly |
| 18 |
|
| 19 |
If you suspect a security issue, do **not** open a public issue or PR. |
| 20 |
|
| 21 |
Follow the process in `SECURITY.md` and use GitHub's private vulnerability reporting flow instead: |
| 22 |
|
| 23 |
- <https://github.com/django-guardian/django-guardian/security> |
| 24 |
|
| 25 |
## Branching and pull requests |
| 26 |
|
| 27 |
`django-guardian` uses a single long-lived branch: |
| 28 |
|
| 29 |
- `main`: active development and release branch |
| 30 |
|
| 31 |
### Which branch should my PR target? |
| 32 |
|
| 33 |
Unless a maintainer explicitly asks otherwise, open pull requests against `main`. |
| 34 |
|
| 35 |
All regular fixes and features are developed and merged on `main`. |
| 36 |
|
| 37 |
### How are releases created? |
| 38 |
|
| 39 |
When a new version is ready, maintainers cut the release from the GitHub web interface and create the corresponding version tag there. |
| 40 |
|
| 41 |
### Recommended workflow |
| 42 |
|
| 43 |
1. Fork the repository. |
| 44 |
2. Clone your fork locally. |
| 45 |
3. Create a focused branch from `main`. |
| 46 |
4. Make the change with tests and documentation updates where relevant. |
| 47 |
5. Run the local checks listed below. |
| 48 |
6. Push your branch and open a PR against `main`. |
| 49 |
|
| 50 |
## Development environment |
| 51 |
|
| 52 |
The repository uses `uv` for dependency management and command execution. |
| 53 |
|
| 54 |
### Initial setup |
| 55 |
|
| 56 |
1. Install `uv`: |
| 57 |
- <https://docs.astral.sh/uv/getting-started/installation/> |
| 58 |
2. Clone your fork of the repository. |
| 59 |
3. Sync the development environment: |
| 60 |
|
| 61 |
```bash |
| 62 |
uv sync --group dev |
| 63 |
``` |
| 64 |
|
| 65 |
This creates and manages a local virtual environment and installs the package together with the development dependencies declared in `pyproject.toml`. |
| 66 |
|
| 67 |
If you want the broader dependency set used by CI for optional database backends, sync the `ci` group instead: |
| 68 |
|
| 69 |
```bash |
| 70 |
uv sync --group ci |
| 71 |
``` |
| 72 |
|
| 73 |
## Local quality checks |
| 74 |
|
| 75 |
Run these before opening or updating a PR. |
| 76 |
|
| 77 |
### Run the main test suite |
| 78 |
|
| 79 |
```bash |
| 80 |
uv run pytest --cov=guardian --cov-report=xml --cov-report=term |
| 81 |
``` |
| 82 |
|
| 83 |
Makefile alias: |
| 84 |
|
| 85 |
```bash |
| 86 |
make test |
| 87 |
``` |
| 88 |
|
| 89 |
### Run the full tox matrix |
| 90 |
|
| 91 |
Use `tox` when you want parity with the supported Python/Django matrix, type-checking envs, docs build envs, and example project checks defined in `tox.ini`. |
| 92 |
|
| 93 |
```bash |
| 94 |
uv run tox run |
| 95 |
``` |
| 96 |
|
| 97 |
To run a single environment: |
| 98 |
|
| 99 |
```bash |
| 100 |
uv run tox run -e core-py313-django51 |
| 101 |
uv run tox run -e type-py313 |
| 102 |
uv run tox run -e docs-py313-django51 |
| 103 |
``` |
| 104 |
|
| 105 |
Makefile alias for the full matrix: |
| 106 |
|
| 107 |
```bash |
| 108 |
make test-all |
| 109 |
``` |
| 110 |
|
| 111 |
### Lint and type-check |
| 112 |
|
| 113 |
```bash |
| 114 |
uv run ruff check . |
| 115 |
uv run mypy ./guardian |
| 116 |
``` |
| 117 |
|
| 118 |
Makefile alias: |
| 119 |
|
| 120 |
```bash |
| 121 |
make lint |
| 122 |
``` |
| 123 |
|
| 124 |
### Auto-format before committing |
| 125 |
|
| 126 |
```bash |
| 127 |
uv run ruff check --fix . |
| 128 |
uv run ruff format . |
| 129 |
``` |
| 130 |
|
| 131 |
Makefile alias: |
| 132 |
|
| 133 |
```bash |
| 134 |
make format |
| 135 |
``` |
| 136 |
|
| 137 |
### Build the documentation |
| 138 |
|
| 139 |
```bash |
| 140 |
uv run mkdocs build |
| 141 |
``` |
| 142 |
|
| 143 |
To preview docs locally: |
| 144 |
|
| 145 |
```bash |
| 146 |
uv run mkdocs serve |
| 147 |
``` |
| 148 |
|
| 149 |
Makefile aliases: |
| 150 |
|
| 151 |
```bash |
| 152 |
make docs |
| 153 |
make docs-serve |
| 154 |
``` |
| 155 |
|
| 156 |
### Migration sanity check |
| 157 |
|
| 158 |
If your change touches models, permissions models, or generated schema state, make sure migrations are in sync: |
| 159 |
|
| 160 |
```bash |
| 161 |
uv run python manage.py makemigrations --check --dry-run |
| 162 |
``` |
| 163 |
|
| 164 |
The tox test environments perform this check automatically for the Django envs. |
| 165 |
|
| 166 |
## Code and review standards |
| 167 |
|
| 168 |
### Tests are required for behavior changes |
| 169 |
|
| 170 |
If you change behavior, fix a bug, optimize performance-sensitive code, or refactor permission logic, add or update tests that prove the change. |
| 171 |
|
| 172 |
`django-guardian` is security-sensitive and tightly integrated with Django's permission framework. A change that "looks right" is not enough; it must be demonstrated through tests. |
| 173 |
|
| 174 |
### Keep changes focused |
| 175 |
|
| 176 |
- Avoid drive-by refactors unrelated to the issue. |
| 177 |
- Preserve public APIs unless the change has been discussed first. |
| 178 |
- Call out any compatibility, migration, or performance impact in the PR description. |
| 179 |
- Update docs for user-visible behavior changes. |
| 180 |
|
| 181 |
### Follow repository tooling |
| 182 |
|
| 183 |
Current repository standards are defined primarily by: |
| 184 |
|
| 185 |
- `pyproject.toml` for dependencies, `ruff`, `mypy`, and `pytest` configuration |
| 186 |
- `tox.ini` for the supported test environments |
| 187 |
- `Makefile` for convenience commands |
| 188 |
|
| 189 |
If a doc page disagrees with those files, treat the configuration files as the source of truth. |
| 190 |
|
| 191 |
### Add yourself to project metadata |
| 192 |
|
| 193 |
If you would like to be credited as a contributor, add your name to the end of the `authors` list in `pyproject.toml`, preserving the existing ordering convention. |
| 194 |
|
| 195 |
## Pull request checklist |
| 196 |
|
| 197 |
Before requesting review, make sure your PR: |
| 198 |
|
| 199 |
- links the relevant issue or clearly explains the context |
| 200 |
- includes tests for code changes |
| 201 |
- passes formatting, linting, typing, and relevant test commands locally |
| 202 |
- updates documentation when behavior or public APIs changed |
| 203 |
- explains any security, performance, or compatibility implications |
| 204 |
|
| 205 |
## Policy on AI and LLM usage in contributions |
| 206 |
|
| 207 |
We recognize that Artificial Intelligence (AI) and Large Language Models (LLMs) like GitHub Copilot, ChatGPT, Claude, and Gemini can accelerate development, assist in debugging, and help draft documentation. |
| 208 |
|
| 209 |
However, to maintain the standards, security, and integrity of `django-guardian`, we strictly prohibit **vibe-coding**: blindly generating and pasting code without understanding how it works. |
| 210 |
|
| 211 |
If you use AI tools to assist in your contribution, you must follow the rules below. |
| 212 |
|
| 213 |
### 1. Absolute developer ownership |
| 214 |
|
| 215 |
You are the sole author and owner of the code you submit. **"The AI generated it" is never a valid excuse** for bugs, security vulnerabilities, licensing problems, or architectural flaws. |
| 216 |
|
| 217 |
By submitting a PR, you are asserting that you understand every line of the change, how it integrates with the codebase, and what edge cases it introduces. |
| 218 |
|
| 219 |
### 2. Zero tolerance for vibe-coding and contribution spam |
| 220 |
|
| 221 |
We expect deliberate, context-aware engineering. |
| 222 |
|
| 223 |
- Do not submit raw, unedited LLM output. |
| 224 |
- Do not generate PRs just to increase contribution counts. |
| 225 |
- Automated or heavily AI-generated PRs that lack human review, project context, or adherence to this repository's standards may be closed without review. |
| 226 |
|
| 227 |
### 3. Verify every API, query, and compatibility claim |
| 228 |
|
| 229 |
LLMs frequently hallucinate APIs, invent nonexistent libraries, and suggest outdated or deprecated patterns. |
| 230 |
|
| 231 |
You must manually verify that AI-assisted changes do not introduce: |
| 232 |
|
| 233 |
- fake Django or Python APIs |
| 234 |
- deprecated Django behavior that will break in supported versions |
| 235 |
- incorrect query patterns that create N+1 issues or permission leakage |
| 236 |
- inaccurate typing, migration, or configuration changes |
| 237 |
|
| 238 |
### 4. Mandatory testing and verification |
| 239 |
|
| 240 |
AI output is probabilistic, not authoritative. Any AI-assisted logic change, refactor, or optimization must be covered by robust tests and verified locally with the repository tooling. |
| 241 |
|
| 242 |
For non-trivial changes, that typically means running some combination of: |
| 243 |
|
| 244 |
- `uv run pytest --cov=guardian --cov-report=xml --cov-report=term` |
| 245 |
- `uv run tox run` |
| 246 |
- `uv run ruff check .` |
| 247 |
- `uv run mypy ./guardian` |
| 248 |
|
| 249 |
If the change affects docs, examples, or release flow, verify those too. |
| 250 |
|
| 251 |
### 5. Security and intellectual property |
| 252 |
|
| 253 |
LLMs are trained on large volumes of public code and can sometimes reproduce copyrighted snippets or reintroduce known vulnerabilities. |
| 254 |
|
| 255 |
It is your responsibility to ensure that your contribution: |
| 256 |
|
| 257 |
- does not violate project licensing expectations |
| 258 |
- follows Django security best practices |
| 259 |
- does not expose private data, unsafe serialization, SQL injection risk, or permission bypasses |
| 260 |
|
| 261 |
### 6. Transparency and disclosure |
| 262 |
|
| 263 |
If a significant portion of your implementation, architecture, or refactoring was drafted with AI assistance, disclose that in the PR description. |
| 264 |
|
| 265 |
Example: |
| 266 |
|
| 267 |
> *Note: I used [Tool Name] to help draft the initial logic for this change. I manually reviewed and adapted the result to fit `django-guardian`, and I added tests and local verification for the final implementation.* |