Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 3 additions & 34 deletions src/sentry/models/organizationmapping.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, ClassVar
from typing import TYPE_CHECKING

from django.db import models
from django.db.models import F
from django.db.models.functions import Now, TruncSecond
from django.utils import timezone

Expand All @@ -12,38 +11,25 @@
from sentry.db.models import BoundedBigIntegerField, sane_repr
from sentry.db.models.base import Model, control_silo_model
from sentry.db.models.indexes import IndexWithPostgresNameLimits
from sentry.db.models.manager.base import BaseManager
from sentry.db.models.manager.base_query_set import BaseQuerySet
from sentry.hybridcloud.rpc import IDEMPOTENCY_KEY_LENGTH, REGION_NAME_LENGTH
from sentry.models.organization import OrganizationStatus

if TYPE_CHECKING:
from sentry.organizations.services.organization import RpcOrganizationMappingFlags


# TODO(cells): remove once all callers have been migrated to cell_name
class OrganizationMappingManager(BaseManager["OrganizationMapping"]):
def get_queryset(self) -> BaseQuerySet[OrganizationMapping]:
# annotate(region_name=...) makes mypy think we're redefining the region_name property
# on the model class, but the annotation only exists on queryset results at runtime.
return super().get_queryset().annotate(region_name=F("cell_name")) # type: ignore[no-redef]


@control_silo_model
class OrganizationMapping(Model):
"""
This model is used to:
* Map org slugs to a specific organization and region
* Map org slugs to a specific organization and cell
* Safely reserve organization slugs via an eventually consistent cross silo workflow
"""

# This model is "autocreated" via an outbox write from the regional `Organization` it
# This model is "autocreated" via an outbox write from the `Organization` in the cell it
# references, so there is no need to explicitly include it in the export.
__relocation_scope__ = RelocationScope.Excluded

# TODO(cells): remove once getsentry callers have been migrated to cell_name
objects: ClassVar[OrganizationMappingManager] = OrganizationMappingManager()

organization_id = BoundedBigIntegerField(db_index=True, unique=True)
slug = models.SlugField(unique=True)
name = models.CharField(max_length=64)
Expand All @@ -55,23 +41,6 @@ class OrganizationMapping(Model):
idempotency_key = models.CharField(max_length=IDEMPOTENCY_KEY_LENGTH)
cell_name = models.CharField(max_length=REGION_NAME_LENGTH, db_column="region_name")

# TODO(cells): remove once all callers have been migrated to cell_name
@property
def region_name(self) -> str:
return self.cell_name

# TODO(cells): remove once getsentry callers have been migrated to cell_name
@region_name.setter
def region_name(self, value: str) -> None:
self.cell_name = value

# TODO(cells): remove this function once getsentry callers have been migrated to cell_name
# This is currently needed by https://github.com/getsentry/getsentry/blob/94673f4686d5fa78e71b8c81addba9a3b33bc64a/tests/getsentry/middleware/integrations/parsers/test_salesforce.py#L97
def update(self, using: str | None = None, **kwargs: Any) -> int:
if "region_name" in kwargs:
kwargs["cell_name"] = kwargs.pop("region_name")
return super().update(using=using, **kwargs)

status = BoundedBigIntegerField(choices=OrganizationStatus.as_choices(), null=True)

# Replicated from the Organization.flags attribute
Expand Down
4 changes: 0 additions & 4 deletions src/sentry/types/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ def is_historic_monolith_region(self) -> bool:
return self.name == settings.SENTRY_MONOLITH_REGION


# TODO(cells): Remove once getsentry import sites are updated
Region = Cell


class RegionResolutionError(Exception):
"""Indicate that a region's identity could not be resolved."""

Expand Down
Loading