SSO Python module shouldn't use gettext.install

Bug #1050061 reported by Michael Terry
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu Single Sign On Client
Status tracked in Trunk
Stable-3-0
Fix Committed
Undecided
Unassigned
Stable-4-0
Fix Released
Undecided
Unassigned
Trunk
Fix Released
Undecided
Michael Terry
ubuntu-sso-client (Ubuntu)
Fix Released
Undecided
Unassigned
Precise
Fix Released
Undecided
Unassigned
Quantal
Fix Released
Undecided
Unassigned

Bug Description

[Impact]
A consumer of the ubuntu_sso python module will have their translations rendered inoperable after importing ubuntu_sso.utils.ui (which happens accidentally easily, like say importing ubuntuone.platform.credentials).

One noticeable side effect of this is that all Deja Dup users that back up to Ubuntu One and have a utf8 filename in the backup, will see an error instead of being able to back up. (bug 989496)

[Test Case]
python
> import ubuntu_sso.utils.ui
> _

If the fault exists, you'll see:
<bound method NullTranslations.ugettext of <gettext.NullTranslations instance at 0x9cbbd0c>>

If everything is fine (and the module didn't define _ in the global context), you'll see:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '_' is not defined

[Regression Potential]
Unexpected regressions might include lack of translations for ubuntu_sso if the patch messes up grabbing those translations.

[Original Report]
In utils/ui.py, the following lines are used:

INSTALL_KWARGS = {}
if sys.version_info < (3,):
    INSTALL_KWARGS["unicode"] = True
gettext.install('ubuntu-sso-client', **INSTALL_KWARGS)

But that causes problems for Python apps that use the module. For example, duplicity ran into a problem where it uses gettext.install, only to be later overridden by ubuntu_sso's gettext.install. It's not suitable for a Python module to attempt to own Python builtins like _().

This can be reproduced like so:
> import gettext
> gettext.install('duplicity')
> print(_)
<bound method NullTranslations.gettext of <gettext.NullTranslations instance at 0xb743ceac>>
> import ubuntu_sso.credentials
> print(_)
<bound method NullTranslations.ugettext of <gettext.NullTranslations instance at 0xb6d4cc0c>>

You see how it's changed to ugettext instead of gettext? And it's switched default domains.

A more suitable thing for ubuntu_sso to do is something like:

t = gettext.translation('ubuntu-sso-client')
_ = t.ugettext

This is what the gettext documentation recommends for modules (http://docs.python.org/library/gettext.html#gettext.NullTranslations.install).

Related branches

dobey (dobey)
Changed in ubuntu-sso-client (Ubuntu Quantal):
milestone: none → ubuntu-12.10-beta-2
Revision history for this message
Michael Terry (mterry) wrote :

See bug 989496 for an example of the kind of issue it can cause (in this case, duplicity merely imports ubuntuone.platform.credentials, which ends up importing ubuntu_sso's ui module).

Michael Terry (mterry)
description: updated
description: updated
Revision history for this message
Michael Terry (mterry) wrote :

I'm proposing this as an SRU. It affects all users of Deja Dup that back up to Ubuntu One (the default) with UTF-8 filenames. I've uploaded a version of the patch from trunk to precise-proposed.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ubuntu-sso-client - 3.99.92-0ubuntu1

---------------
ubuntu-sso-client (3.99.92-0ubuntu1) quantal; urgency=low

  * New upstream release.
    - Merge updated translations from Ubuntu into upstream source.
    - Avoid using gettext.install as it breaks _ for imports. (LP: #1050061)
    - Fix string format handling of register link. (LP: #1052607)
  * debian/ubuntu-sso-client.install:
    - Include the locale files here.
  * debian/control, debian/rules:
    - Require dh-translations always.
    - Only build on dh_python2 using versions of Ubuntu.
 -- Rodney Dawes <email address hidden> Wed, 19 Sep 2012 11:21:46 -0400

Changed in ubuntu-sso-client (Ubuntu Quantal):
status: New → Fix Released
Revision history for this message
Clint Byrum (clint-fewbar) wrote : Please test proposed package

Hello Michael, or anyone else affected,

Accepted ubuntu-sso-client into precise-proposed. The package will build now and be available at http://launchpad.net/ubuntu/+source/ubuntu-sso-client/3.0.2-0ubuntu3 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please change the bug tag from verification-needed to verification-done. If it does not, change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in ubuntu-sso-client (Ubuntu Precise):
status: New → Fix Committed
tags: added: verification-needed
Revision history for this message
Sebastien Bacher (seb128) wrote :

That SRU is waiting to be verified for several weeks, is there any chance you could try the update and confirm if it solves the issue for you (so it can be moved to -updates)?

Revision history for this message
Michael Terry (mterry) wrote :

Since no one else is verifying, I verified my own patch in a VM. Using my reproduction steps in the report, after enabling the proposed repo and updating, I verified that the bug is fixed.

tags: added: verification-done
removed: verification-needed
Revision history for this message
Colin Watson (cjwatson) wrote : Update Released

The verification of this Stable Release Update has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regresssions.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ubuntu-sso-client - 3.0.2-0ubuntu3

---------------
ubuntu-sso-client (3.0.2-0ubuntu3) precise-proposed; urgency=low

  * debian/patches/01_no_gettext_install.patch:
    - Don't pollute global namespace with our version of the gettext
      _() function. Fixes issues with backing up in Deja Dup to Ubuntu
      One with UTF-8 filenames. LP: #1050061
 -- Michael Terry <email address hidden> Thu, 13 Sep 2012 13:11:38 -0400

Changed in ubuntu-sso-client (Ubuntu Precise):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.