Skip to content
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
2 changes: 1 addition & 1 deletion src/sentry/api/endpoints/organization_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def post(self, request: Request, organization_id_or_slug) -> Response:

# Figure out which region the organization being forked lives in.
requesting_region_name = get_local_cell().name
replying_region_name = org_mapping.region_name
replying_region_name = org_mapping.cell_name
if replying_region_name in CANNOT_FORK_FROM_REGION:
return Response(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _check_organization_mapping_integrity(
)
return False

if not update.region_name:
if not update.cell_name:
capture_exception(
OrganizationMappingConsistencyException("Organization mapping must have a region")
)
Expand All @@ -82,7 +82,7 @@ def _check_organization_mapping_integrity(
return False

org_slug_regions_set = {org_slug.cell_name for org_slug in org_slugs}
if update.region_name not in org_slug_regions_set:
if update.cell_name not in org_slug_regions_set:
capture_exception(
OrganizationMappingConsistencyException(
"Mismatched Slug Reservation and Organization Regions"
Expand Down Expand Up @@ -112,7 +112,7 @@ def _upsert_organization_slug_reservation_for_monolith(
).first()
if org_slug_reservation is None:
OrganizationSlugReservation(
cell_name=mapping_update.region_name,
cell_name=mapping_update.cell_name,
slug=mapping_update.slug,
organization_id=organization_id,
user_id=-1,
Expand All @@ -125,7 +125,7 @@ def upsert(self, organization_id: int, update: RpcOrganizationMappingUpdate) ->
name=update.name,
status=update.status,
slug=update.slug,
cell_name=update.region_name,
cell_name=update.cell_name,
require_2fa=update.requires_2fa,
early_adopter=update.early_adopter,
allow_joinleave=update.allow_joinleave,
Expand Down
31 changes: 31 additions & 0 deletions src/sentry/hybridcloud/services/organization_mapping/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
# defined, because we want to reflect on type annotations and avoid forward references.

from datetime import datetime
from typing import Any

from django.utils import timezone
from pydantic import root_validator
from pydantic.fields import Field

from sentry.hybridcloud.rpc import RpcModel
Expand All @@ -16,13 +18,27 @@


class RpcOrganizationMapping(RpcOrganizationSummary):
# TODO(cells): rename to cell_name once `cell_name` is no longer being sent
region_name: str = ""
date_created: datetime = Field(default_factory=timezone.now)
verified: bool = False
customer_id: str | None = None
status: int | None = None
flags: RpcOrganizationMappingFlags = Field(default_factory=RpcOrganizationMappingFlags)

# TODO(cells): remove once region_name -> cell_name rename is complete
@property
def cell_name(self) -> str:
return self.region_name

# TODO(cells): temporary code to accept `cell_name` on the wire before property rename is complete
@root_validator(pre=True)
@classmethod
def _accept_cell_name(cls, values: dict[str, Any]) -> dict[str, Any]:
if "cell_name" in values and "region_name" not in values:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this also check that values['region_name'] is truthy to handle the removal process where a default value will be sent?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think so because:

  • The default value "" isn't really valid here. An org mapping should always have a real cell/region
  • since this runs with pre=True, this is the first step before any other validation or defaults are applied

values["region_name"] = values.pop("cell_name")
return values
Comment on lines +38 to +40
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this intended to be a forwards compatible shim for when the wire format changes to using cell_name?

Copy link
Copy Markdown
Member Author

@lynnagara lynnagara Mar 19, 2026

Choose a reason for hiding this comment

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

Yes. This is the first step so all we can flip all usages of .region_name to .cell_name first here and in getsentry and support both on the wire

2nd step will be to change the wire format

3rd step would be to remove the shim and fully rename the region_name property to cell_name

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That sounds like it will work.



class CustomerId(RpcModel):
value: str | None
Expand All @@ -32,7 +48,22 @@ class RpcOrganizationMappingUpdate(RpcModel):
name: str = ""
status: int = 0
slug: str = ""
# TODO(cells): rename to cell_name once `cell_name` is no longer being sent
region_name: str = ""

# TODO(cells): remove once region_name -> cell_name rename is complete
@property
def cell_name(self) -> str:
return self.region_name

# TODO(cells): temporary code to accept `cell_name` on the wire before property rename is complete
@root_validator(pre=True)
@classmethod
def _accept_cell_name(cls, values: dict[str, Any]) -> dict[str, Any]:
if "cell_name" in values and "region_name" not in values:
values["region_name"] = values.pop("cell_name")
return values

# When not set, no change to customer id performed,
# when set with a CustomerId, the customer_id set to either None or string
customer_id: CustomerId | None = None
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/hybridcloud/test_organizationmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_upsert__customer_id(self) -> None:
name=self.organization.name,
slug=self.organization.slug,
status=self.organization.status,
region_name="us",
cell_name="us",
customer_id=CustomerId(value="99"),
),
)
Expand Down
Loading