Skip to content

Commit 4bd1783

Browse files
ref: deprecate our ArrayField for django's (#93504)
<!-- Describe your PR here. -->
1 parent b3a4bda commit 4bd1783

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

src/sentry/db/models/fields/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from .array import * # NOQA
21
from .bounded import * # NOQA
32
from .citext import * # NOQA
43
from .foreignkey import * # NOQA

src/sentry/db/models/fields/array.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""DO NOT USE ME. USE django.contrib.postgres.fields.array.ArrayField
2+
3+
I am only here for migration compatibility
4+
"""
5+
16
from __future__ import annotations
27

38
import ast

src/sentry/models/releases/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from sentry_relay.exceptions import RelayError
1313
from sentry_relay.processing import parse_release
1414

15-
from sentry.db.models import ArrayField
1615
from sentry.db.models.manager.base_query_set import BaseQuerySet
1716
from sentry.exceptions import InvalidSearchQuery
1817
from sentry.models.releases.release_project import ReleaseProject
@@ -133,7 +132,9 @@ def filter_by_semver(
133132
)
134133
cols = self.model.SEMVER_COLS[: len(semver_filter.version_parts)]
135134
qs = qs.annotate(
136-
semver=Func(*(F(col) for col in cols), function="ROW", output_field=ArrayField())
135+
semver=Func(
136+
*(F(col) for col in cols), function="ROW", output_field=models.JSONField()
137+
)
137138
)
138139
qs = getattr(qs, query_func)(**{f"semver__{semver_filter.operator}": filter_func})
139140
return qs

tests/tools/test_flake8_plugin.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def bad_code():
5757

5858
errors = _run(S003_py)
5959
assert errors == [
60-
"t.py:1:0: S003 Use ``from sentry.utils import json`` instead.",
61-
"t.py:2:0: S003 Use ``from sentry.utils import json`` instead.",
62-
"t.py:3:0: S003 Use ``from sentry.utils import json`` instead.",
63-
"t.py:4:0: S003 Use ``from sentry.utils import json`` instead.",
60+
"t.py:1:0: S003 Use `from sentry.utils import json` instead.",
61+
"t.py:2:0: S003 Use `from sentry.utils import json` instead.",
62+
"t.py:3:0: S003 Use `from sentry.utils import json` instead.",
63+
"t.py:4:0: S003 Use `from sentry.utils import json` instead.",
6464
]
6565

6666

@@ -221,6 +221,14 @@ def test_S012():
221221
"""
222222

223223
expected = [
224-
"t.py:1:0: S012 Use ``from sentry.api.permissions import SentryIsAuthenticated`` instead"
224+
"t.py:1:0: S012 Use `from sentry.api.permissions import SentryIsAuthenticated` instead"
225225
]
226-
assert _run(src, filename="tests/test_example.py") == expected
226+
assert _run(src) == expected
227+
228+
229+
def test_S013():
230+
src = """\
231+
from sentry.db.models.fields.array import ArrayField
232+
"""
233+
expected = ["t.py:1:0: S013 Use `django.contrib.postgres.fields.array.ArrayField` instead"]
234+
assert _run(src) == expected

tools/flake8_plugin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
S002_msg = "S002 print functions or statements are not allowed."
1515

16-
S003_msg = "S003 Use ``from sentry.utils import json`` instead."
16+
S003_msg = "S003 Use `from sentry.utils import json` instead."
1717
S003_modules = frozenset(("json", "simplejson"))
1818

1919
S004_msg = "S004 Use `pytest.raises` instead for better debuggability."
@@ -34,7 +34,9 @@
3434
S011_msg = "S011 Use override_options(...) instead to ensure proper cleanup"
3535

3636
# SentryIsAuthenticated extends from IsAuthenticated and provides additional checks for demo users
37-
S012_msg = "S012 Use ``from sentry.api.permissions import SentryIsAuthenticated`` instead"
37+
S012_msg = "S012 Use `from sentry.api.permissions import SentryIsAuthenticated` instead"
38+
39+
S013_msg = "S013 Use `django.contrib.postgres.fields.array.ArrayField` instead"
3840

3941

4042
class SentryVisitor(ast.NodeVisitor):
@@ -71,6 +73,8 @@ def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
7173
x.name == "IsAuthenticated" for x in node.names
7274
):
7375
self.errors.append((node.lineno, node.col_offset, S012_msg))
76+
elif node.module == "sentry.db.models.fields.array":
77+
self.errors.append((node.lineno, node.col_offset, S013_msg))
7478

7579
self.generic_visit(node)
7680

0 commit comments

Comments
 (0)