Skip to content

Commit

Permalink
ref: have models.User extend Model instead of BaseModel
Browse files Browse the repository at this point in the history
most of our db helpers expected .id to be a Field[int, int] and use Model as the type for that
  • Loading branch information
asottile-sentry committed Jun 18, 2024
1 parent f6337d6 commit 11236e5
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/sentry/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@
from sentry.backup.helpers import ImportFlags
from sentry.backup.sanitize import SanitizableField, Sanitizer
from sentry.backup.scopes import ImportScope, RelocationScope
from sentry.db.models import (
BaseManager,
BaseModel,
BoundedBigAutoField,
control_silo_model,
sane_repr,
)
from sentry.db.models import BaseManager, Model, control_silo_model, sane_repr
from sentry.db.models.utils import unique_db_instance
from sentry.db.postgres.transactions import enforce_constraints
from sentry.integrations.types import EXTERNAL_PROVIDERS, ExternalProviders
Expand Down Expand Up @@ -94,13 +88,12 @@ def get_users_with_only_one_integration_for_provider(


@control_silo_model
class User(BaseModel, AbstractBaseUser):
class User(Model, AbstractBaseUser):
__relocation_scope__ = RelocationScope.User
__relocation_custom_ordinal__ = ["username"]

replication_version: int = 2

id = BoundedBigAutoField(primary_key=True)
username = models.CharField(_("username"), max_length=MAX_USERNAME_LENGTH, unique=True)
# this column is called first_name for legacy reasons, but it is the entire
# display name
Expand Down Expand Up @@ -368,7 +361,7 @@ def merge_to(from_user: User, to_user: User) -> None:
with enforce_constraints(
transaction.atomic(using=router.db_for_write(OrganizationMemberMapping))
):
control_side_org_models: tuple[type[BaseModel], ...] = (
control_side_org_models: tuple[type[Model], ...] = (
OrgAuthToken,
OrganizationMemberMapping,
)
Expand All @@ -383,7 +376,7 @@ def merge_to(from_user: User, to_user: User) -> None:
# While it would be nice to make the following changes in a transaction, there are too many
# unique constraints to make this feasible. Instead, we just do it sequentially and ignore
# the `IntegrityError`s.
user_related_models: tuple[type[BaseModel], ...] = (
user_related_models: tuple[type[Model], ...] = (
Authenticator,
Identity,
UserAvatar,
Expand Down

0 comments on commit 11236e5

Please sign in to comment.