Skip to content
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

Fix: registering a new user with a full name longer than 255 characters #34577

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

DmytroAlipov
Copy link
Contributor

@DmytroAlipov DmytroAlipov commented Apr 23, 2024

Description

Fixing an error when a new user tries registering on the platform with a name longer than 255 characters.

edx.quince-rg.lms  | The above exception was the direct cause of the following exception:
edx.quince-rg.lms  | 
edx.quince-rg.lms  | Traceback (most recent call last):
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
edx.quince-rg.lms  |     response = get_response(request)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response
edx.quince-rg.lms  |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
edx.quince-rg.lms  |     return view_func(*args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/views/generic/base.py", line 104, in view
edx.quince-rg.lms  |     return self.dispatch(request, *args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/utils/decorators.py", line 46, in _wrapper
edx.quince-rg.lms  |     return bound_method(*args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/utils/decorators.py", line 46, in _wrapper
edx.quince-rg.lms  |     return bound_method(*args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/views/decorators/debug.py", line 92, in sensitive_post_parameters_wrapper
edx.quince-rg.lms  |     return view(request, *args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_authn/views/register.py", line 531, in dispatch
edx.quince-rg.lms  |     return super().dispatch(request, *args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
edx.quince-rg.lms  |     response = self.handle_exception(exc)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
edx.quince-rg.lms  |     self.raise_uncaught_exception(exc)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
edx.quince-rg.lms  |     raise exc
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
edx.quince-rg.lms  |     response = handler(request, *args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/utils/decorators.py", line 46, in _wrapper
edx.quince-rg.lms  |     return bound_method(*args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
edx.quince-rg.lms  |     return view_func(*args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/utils/decorators.py", line 46, in _wrapper
edx.quince-rg.lms  |     return bound_method(*args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django_ratelimit/decorators.py", line 27, in _wrapped
edx.quince-rg.lms  |     return fn(request, *args, **kw)
edx.quince-rg.lms  |   File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_authn/views/register.py", line 587, in post
edx.quince-rg.lms  |     response, user = self._create_account(request, data)
edx.quince-rg.lms  |   File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_authn/views/register.py", line 666, in _create_account
edx.quince-rg.lms  |     user = create_account_with_params(request, data)
edx.quince-rg.lms  |   File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_authn/views/register.py", line 211, in create_account_with_params
edx.quince-rg.lms  |     (user, profile, registration) = do_create_account(form, custom_form)
edx.quince-rg.lms  |   File "/edx/app/edxapp/edx-platform/common/djangoapps/student/helpers.py", line 753, in do_create_account
edx.quince-rg.lms  |     profile.save()
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/base.py", line 814, in save
edx.quince-rg.lms  |     self.save_base(
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/base.py", line 877, in save_base
edx.quince-rg.lms  |     updated = self._save_table(
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/base.py", line 1020, in _save_table
edx.quince-rg.lms  |     results = self._do_insert(
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/base.py", line 1061, in _do_insert
edx.quince-rg.lms  |     return manager._insert(
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/manager.py", line 87, in manager_method
edx.quince-rg.lms  |     return getattr(self.get_queryset(), name)(*args, **kwargs)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/query.py", line 1805, in _insert
edx.quince-rg.lms  |     return query.get_compiler(using=using).execute_sql(returning_fields)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql
edx.quince-rg.lms  |     cursor.execute(sql, params)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/debug_toolbar/panels/sql/tracking.py", line 252, in execute
edx.quince-rg.lms  |     return self._record(super().execute, sql, params)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/debug_toolbar/panels/sql/tracking.py", line 177, in _record
edx.quince-rg.lms  |     return method(sql, params)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/backends/utils.py", line 102, in execute
edx.quince-rg.lms  |     return super().execute(sql, params)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/backends/utils.py", line 67, in execute
edx.quince-rg.lms  |     return self._execute_with_wrappers(
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
edx.quince-rg.lms  |     return executor(sql, params, many, context)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
edx.quince-rg.lms  |     return self.cursor.execute(sql, params)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/utils.py", line 91, in __exit__
edx.quince-rg.lms  |     raise dj_exc_value.with_traceback(traceback) from exc_value
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
edx.quince-rg.lms  |     return self.cursor.execute(sql, params)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 75, in execute
edx.quince-rg.lms  |     return self.cursor.execute(query, args)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/MySQLdb/cursors.py", line 179, in execute
edx.quince-rg.lms  |     res = self._query(mogrified_query)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/MySQLdb/cursors.py", line 330, in _query
edx.quince-rg.lms  |     db.query(q)
edx.quince-rg.lms  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/MySQLdb/connections.py", line 255, in query
edx.quince-rg.lms  |     _mysql.connection.query(self, query)
edx.quince-rg.lms  | django.db.utils.DataError: (1406, "Data too long for column 'name' at row 1")
edx.quince-rg.lms  | [23/Apr/2024 11:26:00] "POST /api/user/v2/account/registration/ HTTP/1.1" 500 561223

Error 500 is returned to the user
500

I will also make a fix in Authn MFE so that a request with such a long name will not be sent. But this fix will protect the backend from errors in writing to the database.

In this case, a 400 response will be sent to the user:
400


PS: MR#1242 to Authn MFE

@DmytroAlipov DmytroAlipov requested a review from a team as a code owner April 23, 2024 12:04
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 23, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Apr 23, 2024

Thanks for the pull request, @DmytroAlipov!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/wg-maintenance-edx-platform. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@DmytroAlipov DmytroAlipov added the bug Report of or fix for something that isn't working as intended label Apr 23, 2024
@mphilbrick211 mphilbrick211 added the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Jul 30, 2024
@DmytroAlipov
Copy link
Contributor Author

Hi @mphilbrick211
Friendly ping 😉 Also awaiting merge and related MR

@mphilbrick211
Copy link

Hi @DmytroAlipov - thank you for your patience! We are awaiting review from a Core Contributor.

@farhaanbukhsh
Copy link
Member

@mphilbrick211 I can help with this review :)

Copy link
Contributor

@syedsajjadkazmii syedsajjadkazmii left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks.

@farhaanbukhsh
Copy link
Member

Hey @DmytroAlipov I will review it later today :)

Copy link
Member

@farhaanbukhsh farhaanbukhsh left a comment

Choose a reason for hiding this comment

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

I have added one small comment apart from that the changes look and we should be in a place merge this :)

Thanks for the patience and effort.

@@ -167,6 +167,7 @@ class AccountCreationForm(forms.Form):

name = forms.CharField(
min_length=accounts.NAME_MIN_LENGTH,
max_length=accounts.NAME_MAX_LENGTH,
Copy link
Member

Choose a reason for hiding this comment

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

Instead of relying on system generated string we should add our own error message just like _NAME_TOO_SHORT_MSG this will help us to have have translations for them.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@farhaanbukhsh done 😉

@DmytroAlipov DmytroAlipov force-pushed the fix-name-max-lenght branch 9 times, most recently from 2ec3b58 to e99ec77 Compare November 12, 2024 13:45
Copy link
Member

@farhaanbukhsh farhaanbukhsh left a comment

Choose a reason for hiding this comment

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

👍

  • ✅ I tested this on tutor and tested this with the API calls.
  • ✅ I read through the code
  • ❌ I checked for accessibility issues
  • ❌ Includes documentation
  • ❌ I made sure any change in configuration variables is reflected in the corresponding client's configuration-secure repository.

@farhaanbukhsh farhaanbukhsh merged commit 15aa04b into openedx:master Nov 13, 2024
51 checks passed
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

@DmytroAlipov DmytroAlipov deleted the fix-name-max-lenght branch November 13, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Report of or fix for something that isn't working as intended needs reviewer assigned PR needs to be (re-)assigned a new reviewer open-source-contribution PR author is not from Axim or 2U
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants