Skip to content

Commit 3f03e1e

Browse files
authored
fix(semver): Fix semver backfill when version numbers are larger than a bigint (#26608)
This fixes an edge case where we end up with major/minor/patch/revision numbers that end up larger than a postgres bigint can handle. We just skip these, since we have no way to store them.
1 parent 26c222c commit 3f03e1e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/sentry/migrations/0205_semver_backfill.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ def convert_build_code_to_build_number(build_code):
1515
if build_code is not None:
1616
try:
1717
build_code_as_int = int(build_code)
18-
if build_code_as_int >= 0 and build_code_as_int.bit_length() <= 63:
18+
if validate_bigint(build_code_as_int):
1919
build_number = build_code_as_int
2020
except ValueError:
2121
pass
2222
return build_number
2323

2424

25+
def validate_bigint(value):
26+
return isinstance(value, int) and value >= 0 and value.bit_length() <= 63
27+
28+
2529
UPDATE_QUERY = """
2630
UPDATE sentry_release
2731
SET package = data.package,
@@ -53,6 +57,10 @@ def backfill_semver(apps, schema_editor):
5357
if version_parsed is None:
5458
continue
5559

60+
bigint_fields = ["major", "minor", "patch", "revision"]
61+
if not all(validate_bigint(version_parsed[field]) for field in bigint_fields):
62+
continue
63+
5664
build_code = version_parsed.get("build_code")
5765
build_number = convert_build_code_to_build_number(build_code)
5866
batch.append(

0 commit comments

Comments
 (0)