diff --git a/src/sentry/models/releases/util.py b/src/sentry/models/releases/util.py index be9807bc0f71b1..16b154a6c5b4f6 100644 --- a/src/sentry/models/releases/util.py +++ b/src/sentry/models/releases/util.py @@ -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, diff --git a/src/sentry/search/events/datasets/filter_aliases.py b/src/sentry/search/events/datasets/filter_aliases.py index fd9b7c17ce9fc8..19a6ffd8ff4a64 100644 --- a/src/sentry/search/events/datasets/filter_aliases.py +++ b/src/sentry/search/events/datasets/filter_aliases.py @@ -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: