If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

Parsing error in social_widgets.py if tweet contains accented characters

RESOLVED FIXED

Status

www.mozilla.org
Bedrock
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: agibson, Unassigned)

Tracking

Production
x86
All

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

3 years ago
Our social_widgets.py helper currently throws an error if a tweet contains a hashtag or mention with accented characters, such as this tweet:

https://twitter.com/firefox_es/status/518430450130231296

I managed to fix it locally using hash.encode('utf-8') in our format_tweet_body function here: https://github.com/mozilla/bedrock/blob/master/bedrock/mozorg/helpers/social_widgets.py#L30

But we should probably make this a bit safer so it doesn't bring down a whole page if the function runs into a problem.
(Reporter)

Comment 1

3 years ago
Here's my traceback:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/es-ES/

Django Version: 1.5.9
Python Version: 2.7.5
Installed Applications:
('funfactory',
 'tower',
 'cronjobs',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'commonware.response.cookies',
 'django_nose',
 'product_details',
 'jingo_markdown',
 'jingo_minify',
 'django_statsd',
 'waffle',
 'south',
 'django_sha2',
 'django.contrib.contenttypes',
 'django.contrib.messages',
 'bedrock.base',
 'bedrock.lightbeam',
 'bedrock.firefox',
 'bedrock.foundation',
 'bedrock.gigabit',
 'bedrock.grants',
 'bedrock.legal',
 'bedrock.mozorg',
 'bedrock.newsletter',
 'bedrock.persona',
 'bedrock.press',
 'bedrock.privacy',
 'bedrock.redirects',
 'bedrock.research',
 'bedrock.styleguide',
 'bedrock.tabzilla',
 'bedrock.facebookapps',
 'bedrock.externalfiles',
 'bedrock.security',
 'django_extensions',
 'lib.l10n_utils',
 'captcha',
 'rna',
 'raven.contrib.django.raven_compat')
Installed Middleware:
('bedrock.mozorg.middleware.MozorgRequestTimingMiddleware',
 'django_statsd.middleware.GraphiteMiddleware',
 'bedrock.tabzilla.middleware.TabzillaLocaleURLMiddleware',
 'commonware.middleware.RobotsTagHeader',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'commonware.middleware.FrameOptionsHeader',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'bedrock.mozorg.middleware.CacheMiddleware',
 'dnt.middleware.DoNotTrackMiddleware',
 'lib.l10n_utils.middleware.FixLangFileTranslationsMiddleware')


Traceback:
File "/Users/agibson/Sites/bedrock/vendor/lib/python/django/core/handlers/base.py" in get_response
  113.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Users/agibson/Sites/bedrock/vendor/lib/python/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)
File "/Users/agibson/Sites/bedrock/vendor/lib/python/django/views/generic/base.py" in dispatch
  86.         return handler(request, *args, **kwargs)
File "/Users/agibson/Sites/bedrock/vendor/lib/python/django/views/generic/base.py" in get
  154.         return self.render_to_response(context)
File "/Users/agibson/Sites/bedrock/bedrock/mozorg/views.py" in render_to_response
  280.                                  **response_kwargs)
File "/Users/agibson/Sites/bedrock/lib/l10n_utils/__init__.py" in render
  75.     return django_render(request, template, context, **kwargs)
File "/Users/agibson/Sites/bedrock/vendor/lib/python/django/shortcuts/__init__.py" in render
  53.     return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/Users/agibson/Sites/bedrock/vendor/lib/python/django/template/loader.py" in render_to_string
  177.         return t.render(context_instance)
File "/Users/agibson/Sites/bedrock/vendor/src/jingo/jingo/__init__.py" in render
  195.         return super(Template, self).render(context_dict)
File "/Users/agibson/Sites/bedrock/venv/lib/python2.7/site-packages/jinja2/environment.py" in render
  891.         return self.environment.handle_exception(exc_info, True)
File "/Users/agibson/Sites/bedrock/bedrock/mozorg/templates/mozorg/home/index.html" in top-level template code
  6.   {% include 'mozorg/home/home-new.html' %}
File "/Users/agibson/Sites/bedrock/bedrock/mozorg/templates/mozorg/home/home-new.html" in top-level template code
  93.     <div class="face face-{{ faces[content_id][1] }}"></div>
File "/Users/agibson/Sites/bedrock/bedrock/mozorg/templates/mozorg/base-resp.html" in top-level template code
  5. {% extends "base-resp.html" %}
File "/Users/agibson/Sites/bedrock/bedrock/base/templates/base-resp.html" in top-level template code
  134.     {% block content %}{% endblock %}
File "/Users/agibson/Sites/bedrock/bedrock/mozorg/templates/mozorg/home/home-new.html" in block "content"
  238.                 {{ format_tweet_body(tweet)|safe }}
File "/Users/agibson/Sites/bedrock/bedrock/mozorg/helpers/social_widgets.py" in format_tweet_body
  30.                              % ('%23' + urllib.quote(hash), hash)))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py" in quote
  1282.     return ''.join(map(quoter, s))

Exception Type: KeyError at /
Exception Value: u'\xf1'
Created attachment 8501110 [details] [review]
Link to Github pull-request: https://github.com/mozilla/bedrock/pull/2347

Comment 3

3 years ago
Commits pushed to master at https://github.com/mozilla/bedrock

https://github.com/mozilla/bedrock/commit/0c61d9a8a54e4a2c072e3e37564feb50c13796eb
Fix bug 1079272: Fix unicode error in tweet formatting.

https://github.com/mozilla/bedrock/commit/bf5415de7241c46f4507758ec02f6f2dcb6b574f
Merge pull request #2347 from pmclanahan/fix-tweets-unicode-error-1079272

Fix bug 1079272: Fix unicode error in tweet formatting.

Updated

3 years ago
Status: NEW → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.