diff --git a/src/sentry/db/models/fields/__init__.py b/src/sentry/db/models/fields/__init__.py index 00efcdde8965c5..3d62d30e1210fc 100644 --- a/src/sentry/db/models/fields/__init__.py +++ b/src/sentry/db/models/fields/__init__.py @@ -1,4 +1,3 @@ -from .array import * # NOQA from .bounded import * # NOQA from .citext import * # NOQA from .foreignkey import * # NOQA diff --git a/src/sentry/db/models/fields/array.py b/src/sentry/db/models/fields/array.py index 7aa80341e02873..4daf114fe052b8 100644 --- a/src/sentry/db/models/fields/array.py +++ b/src/sentry/db/models/fields/array.py @@ -1,3 +1,8 @@ +"""DO NOT USE ME. USE django.contrib.postgres.fields.array.ArrayField + +I am only here for migration compatibility +""" + from __future__ import annotations import ast diff --git a/src/sentry/models/releases/util.py b/src/sentry/models/releases/util.py index b5d20544b7dd5e..66fa5b2829f5fe 100644 --- a/src/sentry/models/releases/util.py +++ b/src/sentry/models/releases/util.py @@ -12,7 +12,6 @@ from sentry_relay.exceptions import RelayError from sentry_relay.processing import parse_release -from sentry.db.models import ArrayField from sentry.db.models.manager.base_query_set import BaseQuerySet from sentry.exceptions import InvalidSearchQuery from sentry.models.releases.release_project import ReleaseProject @@ -133,7 +132,9 @@ def filter_by_semver( ) cols = self.model.SEMVER_COLS[: len(semver_filter.version_parts)] qs = qs.annotate( - semver=Func(*(F(col) for col in cols), function="ROW", output_field=ArrayField()) + semver=Func( + *(F(col) for col in cols), function="ROW", output_field=models.JSONField() + ) ) qs = getattr(qs, query_func)(**{f"semver__{semver_filter.operator}": filter_func}) return qs diff --git a/tests/tools/test_flake8_plugin.py b/tests/tools/test_flake8_plugin.py index e0f29162f853e0..43613a7abf9d31 100644 --- a/tests/tools/test_flake8_plugin.py +++ b/tests/tools/test_flake8_plugin.py @@ -57,10 +57,10 @@ def bad_code(): errors = _run(S003_py) assert errors == [ - "t.py:1:0: S003 Use ``from sentry.utils import json`` instead.", - "t.py:2:0: S003 Use ``from sentry.utils import json`` instead.", - "t.py:3:0: S003 Use ``from sentry.utils import json`` instead.", - "t.py:4:0: S003 Use ``from sentry.utils import json`` instead.", + "t.py:1:0: S003 Use `from sentry.utils import json` instead.", + "t.py:2:0: S003 Use `from sentry.utils import json` instead.", + "t.py:3:0: S003 Use `from sentry.utils import json` instead.", + "t.py:4:0: S003 Use `from sentry.utils import json` instead.", ] @@ -221,6 +221,14 @@ def test_S012(): """ expected = [ - "t.py:1:0: S012 Use ``from sentry.api.permissions import SentryIsAuthenticated`` instead" + "t.py:1:0: S012 Use `from sentry.api.permissions import SentryIsAuthenticated` instead" ] - assert _run(src, filename="tests/test_example.py") == expected + assert _run(src) == expected + + +def test_S013(): + src = """\ +from sentry.db.models.fields.array import ArrayField +""" + expected = ["t.py:1:0: S013 Use `django.contrib.postgres.fields.array.ArrayField` instead"] + assert _run(src) == expected diff --git a/tools/flake8_plugin.py b/tools/flake8_plugin.py index 37ceba8bbd4041..9cb13fcfc30f3c 100644 --- a/tools/flake8_plugin.py +++ b/tools/flake8_plugin.py @@ -13,7 +13,7 @@ S002_msg = "S002 print functions or statements are not allowed." -S003_msg = "S003 Use ``from sentry.utils import json`` instead." +S003_msg = "S003 Use `from sentry.utils import json` instead." S003_modules = frozenset(("json", "simplejson")) S004_msg = "S004 Use `pytest.raises` instead for better debuggability." @@ -34,7 +34,9 @@ S011_msg = "S011 Use override_options(...) instead to ensure proper cleanup" # SentryIsAuthenticated extends from IsAuthenticated and provides additional checks for demo users -S012_msg = "S012 Use ``from sentry.api.permissions import SentryIsAuthenticated`` instead" +S012_msg = "S012 Use `from sentry.api.permissions import SentryIsAuthenticated` instead" + +S013_msg = "S013 Use `django.contrib.postgres.fields.array.ArrayField` instead" class SentryVisitor(ast.NodeVisitor): @@ -71,6 +73,8 @@ def visit_ImportFrom(self, node: ast.ImportFrom) -> None: x.name == "IsAuthenticated" for x in node.names ): self.errors.append((node.lineno, node.col_offset, S012_msg)) + elif node.module == "sentry.db.models.fields.array": + self.errors.append((node.lineno, node.col_offset, S013_msg)) self.generic_visit(node)