Skip to content

fix(migration-risk): flag RunPython/RunSQL with an explicit None reverse - #395

Open
Xnadir wants to merge 1 commit into
FROWNINGdev:mainfrom
Xnadir:fix/migration-risk-reverse-none
Open

Xnadir wants to merge 1 commit into
FROWNINGdev:mainfrom
Xnadir:fix/migration-risk-reverse-none

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

RunPython(forward, None), RunPython(forward, reverse_code=None) and RunSQL(sql, reverse_sql=None) are irreversible in Django: RunSQL.reversible is reverse_sql is not None, RunPython.reversible is reverse_code is not None, and migrating backwards raises NotImplementedError("You cannot reverse this operation"). runpython_no_reverse and runsql_no_reverse only fired when the argument was left out, so an explicit None got no warning.

Both rules now share a small _lacks_reverse helper that treats a missing argument or a literal None the same way. A starred positional (RunSQL(sql, *rest)) is still assumed to possibly carry a reverse, as before.

Tests

  • RunSQLTest.test_positive_explicit_none_reverse and RunPythonNoReverseTest.test_positive_explicit_none_reverse check the positional and keyword None forms as subtests. All four subtests fail on main and pass with the change.
  • cd cli && python -m pytest -q: 1431 passed, 6 skipped.
  • ruff check and mypy as in CI: clean.

This change was written with the help of Claude Code (AI). I reviewed it and ran the tests above.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Migration risk checks now report missing reverse operations when the reverse argument is explicitly set to None, as well as when it is omitted, for SQL and Python migrations.

Django treats RunPython(code, None) and RunSQL(sql, reverse_sql=None) as
irreversible, the same as leaving the argument out, but the
runpython_no_reverse and runsql_no_reverse rules only fired when the
argument was missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The migration parser now reports runsql_no_reverse and runpython_no_reverse when the reverse argument is omitted or explicitly None. Tests cover positional and keyword forms. The changelog documents the updated behavior.

Changes: Reverse argument checks

Layer / File(s) Summary
Detect missing reverse arguments
cli/orm_lens/migrations_parser.py, cli/tests/test_migration_risk.py, cli/tests/test_migration_risk_new_rules.py, CHANGELOG.md
A shared check recognizes absent and explicitly None reverse arguments. RunSQL and RunPython checks use it. Tests cover positional and keyword None arguments, and the changelog records the behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: frowningdev

Merge Risk: Minimal · up to 96c69

This change makes the migration linter flag RunSQL and RunPython operations whose reverse argument is explicitly None, the same as when it is omitted. The change is small and tested, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says the fix makes the migration-risk check flag RunPython and RunSQL operations whose reverse argument is an explicit None. The raw summary and PR objectives confirm this is the main change…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title says the fix makes the migration-risk check flag RunPython and RunSQL operations whose reverse argument is an explicit None. The raw summary and PR objectives confirm this is the main change: a shared _lacks_reverse helper treats a missing reverse argument and a literal None alike, and new tests cover the positional and keyword None forms. The title is specific and matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68eb9400-2a72-4bb6-bbb5-fe24955b7baa
Commits

Reviewing files that changed from the base of the PR and between dcee0b6 and 96c692a.

Files selected for processing: 4

  • CHANGELOG.md
  • cli/orm_lens/migrations_parser.py
  • cli/tests/test_migration_risk.py
  • cli/tests/test_migration_risk_new_rules.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant