Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshFerge committed Dec 12, 2024
1 parent a51e71b commit 17c6f80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 40 deletions.
64 changes: 24 additions & 40 deletions src/sentry/models/releases/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,48 +81,32 @@ def filter_by_semver_build(
)
)
if isinstance(build, str):
if build.isdecimal() and validate_bigint(int(build)):
qs = getattr(qs, query_func)(**{f"build_number__{operator}": int(build)})
build = [build]

build_number_filters = Q()
build_code_filters = Q()
for b in build:
if b.isdecimal() and validate_bigint(int(b)):
build_number_filters |= Q(**{f"build_number__{operator}": [int(b)]})
else:
if not build or build.endswith("*"):
qs = getattr(qs, query_func)(build_code__startswith=build[:-1])
else:
qs = getattr(qs, query_func)(build_code=build)

return qs
else:
build_number_filters = Q()
build_code_filters = Q()
for b in build:
if b.isdecimal() and validate_bigint(int(b)):
build_number_filters |= Q(**{f"build_number__{operator}": [int(b)]})
if not b or b.endswith("*"):
build_code_filters |= Q(build_code__startswith=b[:-1])
else:
if not b or b.endswith("*"):
build_code_filters |= Q(build_code__startswith=b[:-1])
else:
build_code_filters |= Q(build_code=b)

if build_number_filters:
qs = getattr(qs, query_func)(build_number_filters)
if build_code_filters:
qs = getattr(qs, query_func)(build_code_filters)

# Handle the case where operator is 'in' separately
if operator == "in":
return qs.filter(
Q(
build_number__in=[
int(b) for b in build if b.isdecimal() and validate_bigint(int(b))
]
)
| Q(
build_code__in=[
b for b in build if not b.isdecimal() or not validate_bigint(int(b))
]
)
)
else:
return qs
build_code_filters |= Q(build_code=b)

if build_number_filters:
qs = getattr(qs, query_func)(build_number_filters)
if build_code_filters:
qs = getattr(qs, query_func)(build_code_filters)

return qs.filter(
Q(build_number__in=[int(b) for b in build if b.isdecimal() and validate_bigint(int(b))])
| Q(
build_code__in=[
b for b in build if not b.isdecimal() or not validate_bigint(int(b))
]
)
)

def filter_by_semver(
self,
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/search/events/datasets/filter_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def semver_filter_converter(
final_operator = Op.NOT_IN
versions = exclude_versions
else:
# TODO: when implementing NOT IN, improve this block to contain the above negation logic,
# and potentially simplify by making single version string into a list with length 1
final_operator = Op.IN
versions = []
for v in version:
Expand Down

0 comments on commit 17c6f80

Please sign in to comment.