Skip to content

improvement: make endpoint migration preview report skipped forms and partial writes #49

Closed

Description

@mojtaba-arvin

Audit finding

The new migrate_endpoints --diff and per-file atomic replacement are useful, but unsupported/dynamic legacy decorator forms are left unchanged without being reported. The user can mistake a partial migration for a complete one.

The command also writes files sequentially. Each replacement is atomic, but the whole directory migration is not transactional: if a later file fails, earlier files remain updated. This matches the current per-file atomicity design, but the CLI/docs must make partial progress explicit.

Acceptance criteria

  1. Report unsupported/skipped legacy decorator occurrences deterministically with file and line information and a safe reason (dynamic value, comments, unsupported syntax, etc.).
  2. Keep skipped source unchanged; never attempt unsafe rewrites.
  3. Include skipped cases in both summary and diff preview output without mixing them with successful rewrites.
  4. Document that --write is atomic per file, not transactional across the directory; report files already applied if a later file fails.
  5. Add tests for multiple files where a later atomic replacement fails, ensuring the first file's successful replacement is accurately reported and the failing file remains intact.
  6. Preserve dry-run defaults, --diff/--write mutual exclusion, encoding, permission bits, and temporary-file cleanup.

Activity

  1. mojtaba-arvin commented on Nov 18, 2026

    @mojtaba-arvin
    OwnerAuthor

    Implementation review and proposed reporting contract (2026-11-18)

    Reviewed the current migrate_endpoints command and its tests on the PR #45 branch.

    Confirmed gaps:

    • _collect_rewrites() returns an empty list when a file cannot be parsed and silently drops decorator calls when _legacy_options() or _rewrite_call() returns None.
    • A legacy-looking call with a dynamic version, backward, or forward value is indistinguishable in output from a file that has no legacy syntax.
    • Decorators containing comments are deliberately not rewritten, but the user receives no reason or line number.
    • Path.rglob() traversal is not explicitly sorted, so a multi-file report is not guaranteed to be deterministic.
    • handle() writes each file immediately and lets a later os.replace() error escape without reporting which earlier files have already been replaced.
    • The tests prove per-file replacement safety, but not multi-file partial-progress reporting.

    Proposed contract

    1. Keep the safe AST rewrite rules unchanged. Add a separate analysis result for skipped legacy occurrences; do not turn unsupported syntax into a rewrite.
    2. Classify only calls that visibly use legacy backward/forward flags. Distinguish dynamic/non-literal values, positional legacy version, duplicate flags, mixed versions + legacy flags, and comments. Do not label modern @endpoint(version=...) calls as skipped.
    3. Report each skipped occurrence as stable relative/path.py:line: reason, sorted by path then source position. A file-level parse error should be reported only when the source visibly contains legacy-decorator markers; otherwise an unrelated syntax error is outside this command's migration scope.
    4. In --diff, keep unified source hunks separate from a Skipped legacy decorators section. In normal preview/write output, report rewritten and skipped counts separately.
    5. Sort discovered paths before processing. Preserve dry-run as default and the current per-file atomic replace/encoding/permission behavior.
    6. On a write failure, retain successful earlier replacements (the documented per-file atomicity contract), but raise a clear CommandError naming the failed file and listing already-applied relative paths. The failing file must remain unchanged and its temp file must be removed.
    7. Document plainly: --write is atomic per file, not transactional across the directory. A user who needs all-or-nothing behavior should run against a clean working tree and inspect the diff/working tree before committing.

    One implementation detail to avoid: do not make _collect_rewrites() return a larger mixed tuple that forces every existing caller to change. Keep the rewrite collector stable where possible and introduce a dedicated analysis helper/result for (rewrites, skipped); preserve the existing pure rewrite tests as a compatibility layer.

    No code has been changed on this issue yet. The implementation should begin only after the output format and skipped-case taxonomy are agreed internally and tests cover deterministic multi-file failure.

  2. mojtaba-arvin commented on Nov 18, 2026

    @mojtaba-arvin
    OwnerAuthor

    Implemented the reporting and partial-progress contract directly on the existing draft PR #45 branch, rather than creating another overlapping migration PR.

    Changes now on head 2a5af01394e6753a0d95cc085c3ec40d387ca394: deterministic sorted file traversal; line-addressable reasons for dynamic/non-literal values, positional versions, duplicate/conflicting flags, **kwargs, comments, and parse failures; a separate skipped-occurrences section in --diff; rewritten/skipped summary counts; and a clear CommandError on write failure listing files already replaced. The failing file remains protected by the existing per-file atomic replace and temp cleanup.

    Added regression tests for each skip category, deterministic output, diff separation, syntax errors, and a two-file failure proving that the first successful file is reported while the second remains unchanged. Updated the Reference docs to state clearly that writes are atomic per file, not transactional across the directory.

    CI for this new head is pending. I will keep the issue open until the full matrix verifies the behavior.

  3. mojtaba-arvin commented on Nov 18, 2026

    @mojtaba-arvin
    OwnerAuthor

    CI feedback on the first migration-reporting head found only a Black formatting failure in migrate_endpoints.py; the Python unit/integration suite, package build, website verification, and most compatibility environments passed on that run. I corrected the formatting and pushed 6c59fe278c75b0b0da99a3c0a828332b78736a6b. The earlier lint failure is not being treated as resolved until the rerun on this exact head completes.

  4. mojtaba-arvin commented on Nov 18, 2026

    @mojtaba-arvin
    OwnerAuthor

    One additional audit catch is now covered: the scanner recognizes aliases imported from django_api_versioning and django_api_versioning.decorators (for example, from django_api_versioning import endpoint as api_endpoint). Without this, those legacy decorators could be silently missed even though their syntax is supported by the package. Added tests for both rewriteable and dynamic aliased calls. Latest PR #45 head is e0a9da1d64973eb5a5a214b01cdc1708919384bb; CI is queued.

  5. mojtaba-arvin commented on Nov 18, 2026

    @mojtaba-arvin
    OwnerAuthor

    Black's exact --diff output is now applied to the command file. The diagnostic-only black --diff . addition to tox.ini has been reverted byte-for-byte to main, so it is not part of PR #45's final diff. Current changed files are only the migration command, its tests, and the Reference documentation. Latest head: aab322b0c3aaac1667b03c9d1fa64c1c2075fdc5; full CI rerun pending.

  6. mojtaba-arvin commented on Nov 18, 2026

    @mojtaba-arvin
    OwnerAuthor

    Latest PR #45 run on aab322b0c3aaac1667b03c9d1fa64c1c2075fdc5: the full Python unit/integration suite passed (including new alias, skip-reporting, and partial-write tests), macOS compatibility passed, and the remaining Windows/tox/lint/package/website jobs are still running. No full-matrix pass claimed yet.

  7. mojtaba-arvin commented on Nov 18, 2026

    @mojtaba-arvin
    OwnerAuthor

    Final verification: PR #45's exact head aab322b0c3aaac1667b03c9d1fa64c1c2075fdc5 has now passed the complete pull-request gate, including the expanded unit/integration tests, lint, package build, website verification, Windows/macOS, every configured Python/Django tox environment, and CodeQL. This closes the implementation and verification work tracked here; the issue can be closed when PR #45 is merged. PR remains Draft pending the overall cross-PR review.

  8. mojtaba-arvin commented on Nov 18, 2026

    @mojtaba-arvin
    OwnerAuthor

    Delivered in consolidated merge #58 → main commit a8b39343c478bb5a8afbe1de20d95a2b10630f37. Migration tooling reports unsupported forms, handles imported aliases, produces deterministic diffs, writes atomically per file and reports partial progress accurately.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions