## TL;DR

DeepSource generated a fix but could not apply it  -  usually the file changed since the analysis ran, or the app lacks write permission. Update the branch, re-run analysis, and apply the fix manually if it still will not apply.

## Error

```text
DeepSource: Autofix could not be applied to src/app.py  -  the file has changed since analysis.
```

## Steps

1. Read the autofix message: it names the file and the reason (changed since analysis, or permission denied). Expected: you know which of the two it is.
2. If the file changed, update the branch and let DeepSource re-analyze, then retry the autofix. Expected: the fix applies to the fresh analysis.
3. If it is a permission issue, check the DeepSource GitHub app permissions (contents: write). Expected: the app can push fix commits.
4. If it still will not apply, copy the suggested diff from the DeepSource dashboard and apply it by hand. Expected: the underlying issue is fixed and the check passes.

## When to use

- DeepSource reports 'autofix could not be applied' on the PR.
- The autofix suggestion itself looks correct.

## When not to use

- DeepSource analysis itself failed  -  fix the analysis configuration instead.
- You disagree with the suggested fix; dismiss it rather than forcing it through.

## Tool compatibility

- DeepSource with autofix enabled.
- GitHub / GitLab / Bitbucket.

## Variant phrasings

### Autofix creates a commit you did not expect

Autofix pushes directly; review the commit before merging.

### Autofix loops on the same issue

The fix may not match your formatter  -  apply manually and adjust.

## Why it happens

Autofix applies a patch computed against the analyzed commit. Any newer commit invalidates the patch context, and without write permission the app cannot push at all  -  so it reports instead of silently failing.

## Edge cases

- Autofix commits can surprise reviewers; mention in the PR that part of the diff is machine-applied.
- If the same autofix keeps failing, the rule may conflict with your formatter  -  disable one of them.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_KOZIJKepAQmsuOaKew3KAA
