Skip to content

Fix patch generation for module() calls missing version or using 0.0.0#329

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-patch-functionality-bug
Draft

Fix patch generation for module() calls missing version or using 0.0.0#329
Copilot wants to merge 3 commits intomainfrom
copilot/fix-patch-functionality-bug

Conversation

Copy link

Copilot AI commented Mar 12, 2026

Two related bugs caused the patch generator to produce wrong or crashing results when a module() call omitted version=/compatibility_level=, or when the release version was 0.0.0.

Root Causes

Wrong attribute patched (PR #326 regression)
parse_MODULE_file_content used a global version= regex that matched the first occurrence in the file. When module() had no version= attribute, the regex hit a bazel_dep() version instead — producing a patch that rewrote the wrong line:

-bazel_dep(name = "platforms", version = "1.0.0")
+bazel_dep(name = "platforms", version = "0.1.4")   # wrong!

AssertionError on None comparison
Version.__eq__ asserted isinstance(other, Version), crashing when mod_file.version is None was compared against a release Version.

Spurious patch for 0.0.0 with no compatibility_level
Bazel defaults compatibility_level to 0. When a module omitted it and the release had major version 0, 0 == None evaluated False, triggering an unnecessary (and potentially empty) patch.

Changes

  • version.pyVersion.__eq__ returns NotImplemented for non-Version operands instead of asserting.
  • bazel_wrapper.pyparse_MODULE_file_content — Scopes version= and compatibility_level= extraction to the module(…) call only (DOTALL for multiline support).
  • bazel_wrapper.py_create_patch_for_module_version_if_mismatch — Rewritten to:
    • Add version = "x.y.z" to module() when absent, rather than replacing an unrelated attribute.
    • Add compatibility_level = N when absent and release major > 0.
    • Treat absent compatibility_level as 0 (Bazel default) when deciding whether a patch is needed.
  • tests/conftest.pymake_update_info accepts an optional module_content override for custom fixture content.
  • New tests — Cover Version.__eq__ with None, parse scoping (ignoring bazel_dep versions, multiline calls, zero version), and all new patch scenarios (missing version with 0.x.y release, missing version with major > 0, 0.0.0 with no compatibility_level).
Original prompt

This section details on the original issue you should resolve

<issue_title>Bug in patch functionality</issue_title>
<issue_description>Seems like the patch functionality has a bug see example: #326

The script shall handle "0.0.0" and no version at all.

  • extend script
  • add appropriate tests
  • adjust documentation</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 12, 2026 15:32
Co-authored-by: AlexanderLanin <5074553+AlexanderLanin@users.noreply.github.com>
…0.0.0 version

Co-authored-by: AlexanderLanin <5074553+AlexanderLanin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug in patch functionality Fix patch generation for module() calls missing version or using 0.0.0 Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Bug in patch functionality

2 participants