Bug 694928 - "import decimal" fails in Turkish locale with "KeyError: 'ROUND_CEiLiNG'"
Summary: "import decimal" fails in Turkish locale with "KeyError: 'ROUND_CEiLiNG'"
Alias: None
Product: Fedora
Classification: Fedora
Component: python
Version: rawhide
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Dave Malcolm
QA Contact: Fedora Extras Quality Assurance
Whiteboard: AcceptedNTH anaconda_trace_hash:80eb1...
Depends On:
Blocks: F15-accepted, F15FinalFreezeExcept
TreeView+ depends on / blocked
Reported: 2011-04-08 22:57 UTC by M KÜRŞAT YALÇIN
Modified: 2011-04-25 16:11 UTC (History)
10 users (show)

Fixed In Version: python-2.7.1-7.fc15
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2011-04-22 02:20:19 UTC
Type: ---

Attachments (Terms of Use)
Attached traceback automatically from anaconda. (196.07 KB, text/plain)
2011-04-08 22:57 UTC, M KÜRŞAT YALÇIN
no flags Details
Attached traceback automatically from anaconda. (196.07 KB, text/plain)
2011-04-08 22:59 UTC, M KÜRŞAT YALÇIN
no flags Details
Attached traceback automatically from anaconda. (196.07 KB, text/plain)
2011-04-08 23:02 UTC, M KÜRŞAT YALÇIN
no flags Details

Description M KÜRŞAT YALÇIN 2011-04-08 22:57:27 UTC
The following was filed automatically by anaconda:
anaconda 14.22 exception report
Traceback (most recent call first):
  File "/usr/lib/python2.7/decimal.py", line 3712, in <module>
    val = globals()[globalname]
  File "/usr/lib/python2.7/site-packages/pyanaconda/iw/partition_gui.py", line 37, in <module>
    from decimal import Decimal
  File "/usr/lib/python2.7/site-packages/pyanaconda/gui.py", line 1241, in setScreen
    loaded = imp.load_module(moduleName, *found)
  File "/usr/lib/python2.7/site-packages/pyanaconda/gui.py", line 1191, in nextClicked
    self.setScreen ()
KeyError: 'ROUND_CEiLiNG'

Comment 1 M KÜRŞAT YALÇIN 2011-04-08 22:57:43 UTC
Created attachment 490881 [details]
Attached traceback automatically from anaconda.

Comment 2 M KÜRŞAT YALÇIN 2011-04-08 22:59:37 UTC
Created attachment 490884 [details]
Attached traceback automatically from anaconda.

Comment 3 M KÜRŞAT YALÇIN 2011-04-08 23:02:49 UTC
Created attachment 490885 [details]
Attached traceback automatically from anaconda.

Comment 4 Dave Malcolm 2011-04-11 21:10:45 UTC
Note to self: LANG appears to be tr_TR.UTF-8

Code in question seems to be here:

  3709  # get rounding method function:
  3710  rounding_functions = [name for name in Decimal.__dict__.keys()
  3711                                      if name.startswith('_round_')]
  3712  for name in rounding_functions:
  3713      # name is like _round_half_even, goes to the global ROUND_HALF_EVEN value.
  3714      globalname = name[1:].upper()
  3715      val = globals()[globalname]
  3716      Decimal._pick_rounding_function[val] = name
  3718  del name, val, globalname, rounding_functions

from 2.7.1, although this has the "val = globals()[globalname]" at line 3715

Comment 5 Dave Malcolm 2011-04-11 21:12:24 UTC
  ['_round_ceiling', '_round_half_up', '_round_half_even', '_round_half_down', '_round_05up', '_round_floor', '_round_down', '_round_up']



Looks like "upper()" is doing something unexpected by the decimal.py module within this locale.

Comment 6 Dave Malcolm 2011-04-11 21:20:48 UTC
How does Anaconda actually set the locale?

I tried reproducing this using
 $ LANG=tr_TR.UTF-8 python -c 'print "round_ceiling".upper()'
in the environment, but wasn't able to reproduce.

Comment 7 Dave Malcolm 2011-04-11 22:11:34 UTC
Here's a minimal recipe for reproducing the string conversion that triggers this:

$ LC_ALL=tr_TR.UTF-8 python -c 'import locale; locale.setlocale(locale.LC_ALL, ""); print "round_ceiling".upper()'

Here's a minimal reproducer for the "import" failure:

$ LC_ALL=tr_TR.UTF-8 python -c 'import locale; locale.setlocale(locale.LC_ALL, ""); import decimal'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python2.7/decimal.py", line 3715, in <module>
    val = globals()[globalname]
KeyError: 'ROUND_CEiLiNG'

Comment 8 Dave Malcolm 2011-04-11 22:19:14 UTC
Or even shorter:
  python -c 'import locale; locale.setlocale(locale.LC_ALL, "tr_TR.UTF-8"); print "round_ceiling".upper()'

This has actually already been reported before, as bug 251491

Similar bug reported here for IronPython:
  http://lists.ironpython.com/pipermail/users-ironpython.com/2007-  October/005865.html

Other instances:

Comment 9 Dave Malcolm 2011-04-11 22:20:05 UTC
A nasty possible workaround:
  import decimal
within the entrypoint to anaconda, before calling locale.setlocale()

Comment 10 Dave Malcolm 2011-04-11 22:23:06 UTC
Also mentioned here:
The interpretation of "upper" and "lower" for unicode is here:

Comment 11 Dave Malcolm 2011-04-11 22:27:18 UTC
A robust fix for this for now may be to convert the str instances to unicode first, then call upper on them, then convert back to str.

This would work since upper() for a unicode instance is locale-independent as per:
(though there seems to have been some debate there).

Comment 12 Dave Malcolm 2011-04-11 22:33:56 UTC
Note to self: works with python 3, as the symbols are already unicode internally.

Comment 13 Dave Malcolm 2011-04-11 22:47:53 UTC
Reported upstream as http://bugs.python.org/issue11830

Comment 14 Dave Malcolm 2011-04-12 15:41:35 UTC
Fixed upstream in 2.7 branch.

Fix committed/pushed to "master" for F16:
  * Tue Apr 12 2011 David Malcolm <dmalcolm@redhat.com> - 2.7.1-7
  - fix "import decimal" in the Turkish locale (patch 131; rhbz#694928)

Working on fixing config snafu on my machine so I can build it in Koji

Comment 15 Dave Malcolm 2011-04-12 16:08:31 UTC
Building python-2.7.1-7.fc16 into master:

I also committed/pushed to "f15"; building python-2.7.1-7.fc15 there as:

Comment 16 Dave Malcolm 2011-04-13 21:18:43 UTC
From my reading of this,  any import of Anaconda's pyanaconda.iw.partition_gui module whilst in the Turkish locale will cause a failure of the installer.

This code is referenced by gui
    "partition" : ("partition_gui", "PartitionWindow"),
and it looks like doing so is mandatory for all installs.

pyanaconda/storage/size.py also imports the "decimal" module.

So it looks likely that this bug will block all installations in the Turkish locale.

Added to "F15Blocker" and marked with "CommonBugs".

Comment 17 Fedora Update System 2011-04-13 21:29:34 UTC
python-2.7.1-7.fc15 has been submitted as an update for Fedora 15.

Comment 18 Adam Williamson 2011-04-13 21:30:07 UTC
Tested for F15 Beta purposes: I confirm this bug exists in F15 Beta, but you only hit it if you go to the custom partitioning screen; if you don't use that screen (not using it is the click-straight-through case, btw) you dodge the bug.

Proposing as nice-to-have for final (it doesn't quite hit blocker criteria, IMO), we will document for Beta. The fix will certainly get in for final anyway if it's submitted now.

Comment 19 Fedora Update System 2011-04-14 00:35:45 UTC
Package python-2.7.1-7.fc15:
* should fix your issue,
* was pushed to the Fedora 15 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing python-2.7.1-7.fc15'
as soon as you are able to.
Please go to the following url:
then log in and leave karma (feedback).

Comment 20 Fedora Update System 2011-04-22 02:20:13 UTC
python-2.7.1-7.fc15 has been pushed to the Fedora 15 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 21 Tim Flink 2011-04-25 16:11:16 UTC
Discussed at the 2011-04-15 blocker bug review meeting (updating the bug in case it is re-opened).

This causes problems in anaconda and possibly other packages but doesn't clearly hit any release criteria - accepted as F15 NTH.

Note You need to log in before you can comment on or make changes to this bug.