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: LANGUAGE_COOKIE_NAME is not set by default #507

Closed

Conversation

cmltaWt0
Copy link

@cmltaWt0 cmltaWt0 commented Oct 7, 2021

Regression caused by https://github.com/edx/edx-platform/pull/28796

Details:

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

> production.py

LANGUAGE_COOKIE_NAME = ENV_TOKENS.get('LANGUAGE_COOKIE', None) or ENV_TOKENS.get('LANGUAGE_COOKIE_NAME')

Exception:

2021-10-07 20:26:57,299 INFO 8 [audit] [user 3] [ip 172.19.0.1] models.py:2723 - Login success - user.id: 3
2021-10-07 20:26:57,318 INFO 8 [openedx_events.tooling] [user 3] [ip 172.19.0.1] tooling.py:160 - Responses of the Open edX Event <org.openedx.learning.auth.session.login.completed.v1>:
[]
2021-10-07 20:26:57,429 ERROR 8 [root] [user 3] [ip 172.19.0.1] signals.py:22 - Uncaught exception from None
Traceback (most recent call last):
  File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/openedx/venv/lib/python3.8/site-packages/django/utils/deprecation.py", line 96, in __call__
    response = self.process_response(request, response)
  File "./openedx/core/djangoapps/lang_pref/middleware.py", line 93, in process_response
    response.delete_cookie(
  File "/openedx/venv/lib/python3.8/site-packages/django/http/response.py", line 216, in delete_cookie
    secure = key.startswith(('__Secure-', '__Host-'))
AttributeError: 'NoneType' object has no attribute 'startswith'

@cmltaWt0 cmltaWt0 marked this pull request as ready for review October 7, 2021 22:11
Copy link
Contributor

@pcliupc pcliupc left a comment

Choose a reason for hiding this comment

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

Looks good to me. May also need to update Changelog accordingly.

Copy link
Contributor

@regisb regisb left a comment

Choose a reason for hiding this comment

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

Thanks for your PR @cmltaWt0! I understand that you are trying to address a misconfiguration of the edx-platform production settings. Indeed, in the production settings of edx-platform, we currently have (source):

LANGUAGE_COOKIE_NAME = ENV_TOKENS.get('LANGUAGE_COOKIE', None) or ENV_TOKENS.get('LANGUAGE_COOKIE_NAME')

This is all the more unfortunate that the common settings provide a good default value for this setting (source):

LANGUAGE_COOKIE_NAME = "openedx-language-preference"

So I think it would be better if the edx-platform settings could be fixed upstream:

LANGUAGE_COOKIE_NAME = ENV_TOKENS.get('LANGUAGE_COOKIE') or ENV_TOKENS.get('LANGUAGE_COOKIE_NAME', LANGUAGE_COOKIE_NAME)

I understand that it might be easier to get a PR merged in the Tutor nightly branch than in edx-platform. So what I suggest is that you open a PR on the edx-platform repo; if it cannot be immediately merged, get back here and we'll merge this one. Once your PR is merged in edx-platform, revert your change in the Tutor nightly branch.

What do you think?

@@ -35,6 +35,7 @@
"EMAIL_USE_TLS": {{ "true" if SMTP_USE_TLS else "false" }},
"HTTPS": "{{ "on" if ENABLE_HTTPS else "off" }}",
"LANGUAGE_CODE": "{{ LANGUAGE_CODE }}",
"LANGUAGE_COOKIE_NAME": "{{ LANGUAGE_COOKIE_NAME }}",
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather avoid adding too much stuff to the env.json files. Could we replace these two additions (to lms.env.json and cms.env.json) by a single addition to the apps/openedx/settings/partials/common_all.py template?

Copy link
Author

Choose a reason for hiding this comment

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

Will try this.

@@ -48,6 +48,7 @@ JWT_COMMON_SECRET_KEY: "{{ OPENEDX_SECRET_KEY }}"
JWT_RSA_PRIVATE_KEY: "{{ 2048|rsa_private_key }}"
K8S_NAMESPACE: "openedx"
LANGUAGE_CODE: "en"
LANGUAGE_COOKIE_NAME: "openedx-language-preference"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should avoid adding Tutor configuration variables for every edx-platform setting. My rule of thumb is that if a setting can be easily overridden by a Tutor plugin (e.g: with at most 2-3 patches) then we should not create a new Tutor setting. Instead, Tutor should provide a good default out of the box.

Copy link
Author

Choose a reason for hiding this comment

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

Great. Totally agree.

@cmltaWt0
Copy link
Author

Thanks for your PR @cmltaWt0! I understand that you are trying to address a misconfiguration of the edx-platform production settings. Indeed, in the production settings of edx-platform, we currently have (source):

LANGUAGE_COOKIE_NAME = ENV_TOKENS.get('LANGUAGE_COOKIE', None) or ENV_TOKENS.get('LANGUAGE_COOKIE_NAME')

This is all the more unfortunate that the common settings provide a good default value for this setting (source):

LANGUAGE_COOKIE_NAME = "openedx-language-preference"

So I think it would be better if the edx-platform settings could be fixed upstream:

LANGUAGE_COOKIE_NAME = ENV_TOKENS.get('LANGUAGE_COOKIE') or ENV_TOKENS.get('LANGUAGE_COOKIE_NAME', LANGUAGE_COOKIE_NAME)

I understand that it might be easier to get a PR merged in the Tutor nightly branch than in edx-platform. So what I suggest is that you open a PR on the edx-platform repo; if it cannot be immediately merged, get back here and we'll merge this one. Once your PR is merged in edx-platform, revert your change in the Tutor nightly branch.

What do you think?

Thanks a lot in such a good analysis. I was thinking the same way and didn't want to add any line of code to the tutor codebase but fix it in upstream.

Will create a PR to the edx-platform and let's hope it will be merged quickly. Simultaneously will changes this PR (to have plan B) based on the best practices you mentioned.

@regisb
Copy link
Contributor

regisb commented Oct 14, 2021

@cmltaWt0 I've had to git push --force the nightly branch -- bad, I know, but I only recently officialised the existence of the nightly branch by merging #494. Can you please rebase?

Regression caused by https://github.com/edx/edx-platform/pull/28796

Details:

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

> production.py

LANGUAGE_COOKIE_NAME = ENV_TOKENS.get('LANGUAGE_COOKIE', None) or ENV_TOKENS.get('LANGUAGE_COOKIE_NAME')
```
@cmltaWt0 cmltaWt0 force-pushed the cmltaWt0/language_cookie_name branch from ea0b4a6 to a3e436e Compare October 19, 2021 07:28
@cmltaWt0
Copy link
Author

@cmltaWt0 I've had to git push --force the nightly branch -- bad, I know, but I only recently officialised the existence of the nightly branch by merging #494. Can you please rebase?

Done. Yet not started to work on your review. Will try to finish this week.

@cmltaWt0
Copy link
Author

Adding upstream PR https://github.com/edx/edx-platform/pull/29096

Have to keep in mind that maple quick fix should be reverted after upstream PR is merged due to losing the ability to use $LMS_CFG as a point to override the LANGUAGE_COOKIE_NAME for different envs easily and dynamically.

@cmltaWt0
Copy link
Author

Actually I'm closing this PR as not needed anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Won't fix
Development

Successfully merging this pull request may close these issues.

3 participants