-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
ref(cells): update region_name to cell_name in rpc dataclasses #111039
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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: | ||
| values["region_name"] = values.pop("cell_name") | ||
| return values | ||
|
Comment on lines
+38
to
+40
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds like it will work. |
||
|
|
||
|
|
||
| class CustomerId(RpcModel): | ||
| value: str | None | ||
|
|
@@ -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 | ||
|
|
||
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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:
""isn't really valid here. An org mapping should always have a real cell/regionpre=True, this is the first step before any other validation or defaults are applied