Skip to content

fix: use common default for LANGUAGE_COOKIE_NAME - #29096

Merged
dianakhuang merged 1 commit into
openedx:masterfrom
cmltaWt0:cmltaWt0/fix/language_cookie_name
Oct 25, 2021
Merged

fix: use common default for LANGUAGE_COOKIE_NAME#29096
dianakhuang merged 1 commit into
openedx:masterfrom
cmltaWt0:cmltaWt0/fix/language_cookie_name

Conversation

@cmltaWt0

@cmltaWt0 cmltaWt0 commented Oct 23, 2021

Copy link
Copy Markdown
Contributor

Changes:

  • effectively use default LANGUAGE_COOKIE_NAME value from common.py for cases when there is no
    LANGUAGE_COOKIE and LANGUAGE_COOKIE_NAME in ENV_TOKENS

Description

Fix regression introduced in https://github.com/edx/edx-platform/pull/28796
The defaults from lms/envs/common.py and cms/envs/common.py aren't used.
This causes login exception in case LANGUAGE_COOKIE_NAME is absent in ENV_TOKENS.
Actually this happened for tutor installation overhangio/tutor#507 and avoided temporary by settings LANGUAGE_COOKIE_NAME in common_all.py for maple release.

Supporting information

Original PR: https://github.com/edx/edx-platform/pull/28796

Testing instructions

To test it in devstack just remove LANGUAGE_COOKIE from /edx/etc/lms.yml and try to login into LMS or Studio.

root@lms:/edx/app/edxapp/edx-platform# cat $LMS_CFG | grep LANGUAGE_COOKIE
LANGUAGE_COOKIE: openedx-language-preference

Login to the LMS and get the Error:

image

edx.devstack.lms                  | 2021-10-23 12:45:08,090 ERROR 269 [root] [user 8] [ip 172.28.0.1] signals.py:22 - Uncaught exception from None
edx.devstack.lms                  | Traceback (most recent call last):
edx.devstack.lms                  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
edx.devstack.lms                  |     response = get_response(request)
edx.devstack.lms                  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/utils/deprecation.py", line 119, in __call__
edx.devstack.lms                  |     response = self.process_response(request, response)
edx.devstack.lms                  |   File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/lang_pref/middleware.py", line 93, in process_response
edx.devstack.lms                  |     response.delete_cookie(
edx.devstack.lms                  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/http/response.py", line 252, in delete_cookie
edx.devstack.lms                  |     key.startswith(('__Secure-', '__Host-')) or
edx.devstack.lms                  | AttributeError: 'NoneType' object has no attribute 'startswith'
edx.devstack.lms                  | Internal Server Error: /api/user/v1/account/login_session/
edx.devstack.lms                  | Traceback (most recent call last):
edx.devstack.lms                  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
edx.devstack.lms                  |     response = get_response(request)
edx.devstack.lms                  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/utils/deprecation.py", line 119, in __call__
edx.devstack.lms                  |     response = self.process_response(request, response)
edx.devstack.lms                  |   File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/lang_pref/middleware.py", line 93, in process_response
edx.devstack.lms                  |     response.delete_cookie(
edx.devstack.lms                  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/http/response.py", line 252, in delete_cookie
edx.devstack.lms                  |     key.startswith(('__Secure-', '__Host-')) or
edx.devstack.lms                  | AttributeError: 'NoneType' object has no attribute 'startswith'
edx.devstack.lms                  | 2021-10-23 12:45:08,183 ERROR 269 [django.request] [user 8] [ip 172.28.0.1] log.py:224 - Internal Server Error: /api/user/v1/account/login_session/
edx.devstack.lms                  | Traceback (most recent call last):
edx.devstack.lms                  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
edx.devstack.lms                  |     response = get_response(request)
edx.devstack.lms                  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/utils/deprecation.py", line 119, in __call__
edx.devstack.lms                  |     response = self.process_response(request, response)
edx.devstack.lms                  |   File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/lang_pref/middleware.py", line 93, in process_response
edx.devstack.lms                  |     response.delete_cookie(
edx.devstack.lms                  |   File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/django/http/response.py", line 252, in delete_cookie
edx.devstack.lms                  |     key.startswith(('__Secure-', '__Host-')) or
edx.devstack.lms                  | AttributeError: 'NoneType' object has no attribute 'startswith'
edx.devstack.lms                  | [23/Oct/2021 12:45:08] "POST /api/user/v1/account/login_session/ HTTP/1.1" 500 311151

LanguagePreferenceMiddleware do the following:

response.delete_cookie(
    settings.LANGUAGE_COOKIE_NAME,
    domain=settings.SHARED_COOKIE_DOMAIN
)
caused an Exception due to absence of LANGUAGE_COOKIE_NAME settings variable

Also there are tons of code in the platform with direct accessing to the lang setting as settings.LANGUAGE_COOKIE_NAME

@openedx-webhooks openedx-webhooks added needs triage open-source-contribution PR author is not from Axim or 2U labels Oct 23, 2021
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @cmltaWt0! I've created OSPR-6161 to keep track of it in JIRA, where we prioritize reviews. Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

Changes:
- use default LANGUAGE_COOKIE_NAME value from common for cases when there is no
`LANGUAGE_COOKIE` and `LANGUAGE_COOKIE_NAME` in ENV_TOKENS
@cmltaWt0
cmltaWt0 force-pushed the cmltaWt0/fix/language_cookie_name branch from c97cbaa to 9acc82f Compare October 23, 2021 13:15
@edx-status-bot

Copy link
Copy Markdown

Your PR has finished running tests. There were no failures.

@natabene

Copy link
Copy Markdown
Contributor

@cmltaWt0 Thank you for your contribution. Is this ready for our review?

@cmltaWt0

Copy link
Copy Markdown
Contributor Author

@cmltaWt0 Thank you for your contribution. Is this ready for our review?

Yes. It's ready.

@dianakhuang dianakhuang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks so much for this fix!

@dianakhuang
dianakhuang merged commit acd83d1 into openedx:master Oct 25, 2021
@openedx-webhooks

Copy link
Copy Markdown

@cmltaWt0 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

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

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged open-source-contribution PR author is not from Axim or 2U

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants