Skip to content

Commit

Permalink
Revert "ref: fix typing for sentry.web.forms.accounts (#83575)"
Browse files Browse the repository at this point in the history
This reverts commit 46eed58.

Co-authored-by: asottile-sentry <[email protected]>
  • Loading branch information
getsentry-bot and asottile-sentry committed Jan 16, 2025
1 parent 5347f6a commit 8a4f246
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ module = [
"sentry.testutils.cases",
"sentry.utils.auth",
"sentry.utils.committers",
"sentry.web.forms.accounts",
"sentry.web.frontend.auth_login",
"sentry.web.frontend.auth_organization_login",
"sentry.web.frontend.base",
Expand Down
25 changes: 13 additions & 12 deletions src/sentry/web/forms/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class AuthenticationForm(forms.Form):
"inactive": _("This account is inactive."),
}

def __init__(self, request: HttpRequest, *args: Any, **kwargs: Any) -> None:
def __init__(self, request: HttpRequest | None = None, *args: Any, **kwargs: Any) -> None:
"""
If request is passed in, the form will validate that cookies are
enabled. Note that the request (a HttpRequest object) must have set a
cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before
running this validation.
"""
self.request = request
self.user_cache: User | None = None
self.user_cache = None
super().__init__(*args, **kwargs)

# Set the label for the "username" field.
Expand Down Expand Up @@ -128,10 +128,11 @@ def clean(self) -> dict[str, Any] | None:
return self.cleaned_data

def check_for_test_cookie(self):
if not self.request.session.test_cookie_worked():
raise forms.ValidationError(self.error_messages["no_cookies"])
else:
self.request.session.delete_test_cookie()
if self.request:
if not self.request.session.test_cookie_worked():
raise forms.ValidationError(self.error_messages["no_cookies"])
else:
self.request.session.delete_test_cookie()

def get_user_id(self):
if self.user_cache:
Expand Down Expand Up @@ -169,7 +170,7 @@ class PasswordlessRegistrationForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not newsletter.backend.is_enabled():
if not newsletter.is_enabled():
del self.fields["subscribe"]
else:
# NOTE: the text here is duplicated within the ``NewsletterConsent`` component
Expand Down Expand Up @@ -205,8 +206,8 @@ def save(self, commit=True):
if commit:
user.save()
if self.cleaned_data.get("subscribe"):
newsletter.backend.create_or_update_subscriptions(
user, list_ids=newsletter.backend.get_default_list_ids()
newsletter.create_or_update_subscriptions(
user, list_ids=newsletter.get_default_list_ids()
)
return user

Expand All @@ -219,7 +220,7 @@ class RegistrationForm(PasswordlessRegistrationForm):
def clean_password(self):
password = self.cleaned_data["password"]
password_validation.validate_password(
password, user=User(username=self.cleaned_data["username"])
password, user=User(username=self.cleaned_data.get("username"))
)
return password

Expand All @@ -229,8 +230,8 @@ def save(self, commit=True):
if commit:
user.save()
if self.cleaned_data.get("subscribe"):
newsletter.backend.create_or_update_subscriptions(
user, list_ids=newsletter.backend.get_default_list_ids()
newsletter.create_or_update_subscriptions(
user, list_ids=newsletter.get_default_list_ids()
)
return user

Expand Down

0 comments on commit 8a4f246

Please sign in to comment.