mathesar-foundation / mathesar

Web application providing an intuitive user experience to databases.
https://mathesar.org/
GNU General Public License v3.0
2.36k stars 327 forks source link

Error when trying to reset password of other user #3528

Closed seancolsen closed 5 months ago

seancolsen commented 5 months ago

Steps to reproduce

  1. Set up another Mathesar user (other than the one you're logged in as).

  2. Edit the another user and try to reset their password.

  3. Observe this error message:

    image

    An API request is made to /api/ui/v0/users/2/password_reset/ which returns a Django error

    AttributeError at /api/ui/v0/users/2/password_reset/

    'PasswordResetSerializer' object has no attribute 'validate_password'

    Traceback ``` Environment: Request Method: POST Request URL: http://localhost:8000/api/ui/v0/users/2/password_reset/ Django Version: 4.2.10 Python Version: 3.9.19 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'whitenoise.runserver_nostatic', 'django.contrib.staticfiles', 'rest_framework', 'django_filters', 'django_property_filter', 'drf_spectacular', 'mathesar'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'mathesar.middleware.CursorClosedHandlerMiddleware', 'mathesar.middleware.PasswordChangeNeededMiddleware', 'django_userforeignkey.middleware.UserForeignKeyMiddleware', 'django_request_cache.middleware.RequestCacheMiddleware'] Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view return view_func(*args, **kwargs) File "/usr/local/lib/python3.9/site-packages/rest_framework/viewsets.py", line 125, in view return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch response = self.handle_exception(exc) File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 466, in handle_exception response = exception_handler(exc, context) File "/code/mathesar/exception_handlers.py", line 63, in mathesar_exception_handler raise exc File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, **kwargs) File "/code/mathesar/api/ui/viewsets/users.py", line 29, in password_reset serializer.is_valid(raise_exception=True) File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 235, in is_valid raise ValidationError(self.errors) File "/code/mathesar/api/exceptions/mixins.py", line 98, in errors pretty_errors = self.build_pretty_errors(ugly_errors) File "/code/mathesar/api/exceptions/mixins.py", line 64, in build_pretty_errors pretty.extend(self.get_field_error_entries(errors[error_type], field)) File "/usr/local/lib/python3.9/site-packages/rest_framework_friendly_errors/mixins.py", line 180, in get_field_error_entries return [self.get_field_error_entry(error, field) for error in errors] File "/usr/local/lib/python3.9/site-packages/rest_framework_friendly_errors/mixins.py", line 180, in return [self.get_field_error_entry(error, field) for error in errors] File "/usr/local/lib/python3.9/site-packages/rest_framework_friendly_errors/mixins.py", line 168, in get_field_error_entry validator = getattr(self, "validate_%s" % field.field_name) Exception Type: AttributeError at /api/ui/v0/users/2/password_reset/ Exception Value: 'PasswordResetSerializer' object has no attribute 'validate_password' ```

I can reproduce this on the latest develop branch as well as the most recent release (Mathesar 0.1.6).

camicacace commented 5 months ago

Hi, can I work on this issue?

seancolsen commented 5 months ago

Sure, @camicacace you're welcome to submit a PR. Ask here or in Matrix if you have any questions.