Skip to content

ref: deprecate our ArrayField for django's #93504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/sentry/db/models/fields/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .array import * # NOQA
from .bounded import * # NOQA
from .citext import * # NOQA
from .foreignkey import * # NOQA
Expand Down
5 changes: 5 additions & 0 deletions src/sentry/db/models/fields/array.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/sentry/models/releases/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
)
Comment on lines +135 to +137
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is a little weird -- technically this isn't json but it also wasn't a postgres array and was just working by accident

this generates the same sql as before and seems to work the same from what I can tell

)
qs = getattr(qs, query_func)(**{f"semver__{semver_filter.operator}": filter_func})
return qs
Expand Down
20 changes: 14 additions & 6 deletions tests/tools/test_flake8_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
]


Expand Down Expand Up @@ -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
8 changes: 6 additions & 2 deletions tools/flake8_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
Loading