[Django] #25640: language error [IMPORTANT: cannot render templates]-- fixed -- please patch Django 1.8

7 views
Skip to first unread message

Django

unread,
Oct 30, 2015, 2:08:13 AM10/30/15
to django-...@googlegroups.com
#25640: language error [IMPORTANT: cannot render templates]-- fixed -- please patch
Django 1.8
-------------------------+-------------------------------------------------
Reporter: | Owner: Dan
literati |
Type: Bug | Status: new
Component: | Version: 1.8
Packaging |
Severity: Release | Keywords: get_language_bidi,
blocker | render_to_string, check_for_language
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
#UPDATE: October 30, 2015 Django 1.8, Ubuntu Server 14.04, Apache 2.4
#1 note that by the time automatic notifications were implemented,
#I used crontab to schedule some recurrent events
#files with the name like 'task8am.sh' load a module through Django shell
#iTo render templates I used a Django shortcut - render_to_string
#while testing I found that this does not work and return an error.
#This can be easily replicated by just doing something like that:
#python3 manage.py shell
#some boilerplatecode
#a = render_to_string('template', {'context': 222 })
#After a little bit of peeking into the issue, I was able to troubleshoot
it and edited some code in
#/usr/local/lib/python3.4/dist-
packages/django/utils/translation/trans_real.py
#It seems that check_for_language and get_language_bidi methods are not
willing
#to accept None values. I hope it will be resolved in the following
versions of
#Django, but for now, here is my patch:
#256 def get_language_bidi():
#257 """
#258 Returns selected language's BiDi layout.
#259
#260 * False = left-to-right layout
#261 * True = right-to-left layout
#262 """
#263 base_lang = get_language()
#264 if base_lang is None:
#265 return False
#266 base_lang = get_language().split('-')[0]
#267 return base_lang in settings.LANGUAGES_BIDI
########
########
#400 @lru_cache.lru_cache(maxsize=1000)
#401 def check_for_language(lang_code):
#402 """
#403 Checks whether there is a global language file for the given
language
#404 code. This is used to decide whether a user-provided language is
#405 available.
#406
#407 lru_cache should have a maxsize to prevent from memory exhaustion
attacks,
#408 as the provided language codes are taken from the HTTP request.
See also
#409 <https://www.djangoproject.com/weblog/2007/oct/26/security-fix/>.
#410 """
#411 # First, a quick check to make sure lang_code is well-formed
(#21458)
#412 if lang_code is None or not language_code_re.search(lang_code):
#413 return False
#414 for path in all_locale_paths():
#415 if gettext_module.find('django', path,
[to_locale(lang_code)]) is not None:
#416 return True
#417 return False

--
Ticket URL: <https://code.djangoproject.com/ticket/25640>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 30, 2015, 4:28:10 AM10/30/15
to django-...@googlegroups.com
#25640: language error [IMPORTANT: cannot render templates]-- fixed -- please patch
Django 1.8
-------------------------------------+-------------------------------------
Reporter: literati | Owner: Dan
Type: Bug | Status: closed
Component: Packaging | Version: 1.8
Severity: Release blocker | Resolution: duplicate
Keywords: get_language_bidi, | Triage Stage:
render_to_string, | Unreviewed
check_for_language |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0


Comment:

That was fixed in Django 1.8.1 (#24569). Please always use the latest
minor version before reporting a bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/25640#comment:1>

Reply all
Reply to author
Forward
0 new messages