google-code-export / appengine-devappserver2-experiment

Automatically exported from code.google.com/p/appengine-devappserver2-experiment
0 stars 0 forks source link

Two unequal instances of the decimal.Decimal class are being imported #62

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

We're using SQLAlchemy and when I retrieve an instance from the database with a 
Numeric property ((ex. decimal.Decimal, 
http://docs.sqlalchemy.org/en/rel_0_8/core/types.html#sqlalchemy.types.Numeric),
 the type of the property is different than the one I import (ex. `from decimal 
import Decimal`), which causes a lot of errors.

For example:
    `isinstance(lineitem.quantity, Decimal)` returns False.

    Running `quantize` on the property of the entity from the database
        > lineitem.quantity.quantize(Decimal('0.01')
    Raises the following error:
        TypeError: Unable to convert 0.01 to Decimal

If I check the id() of both `type(lineitem.quantity)` and `id(Decimal)`, I get 
different ids:
    INFO     2013-03-27 15:33:46,346 __init__.py:243] *** id(type(lineitem.quantity)): 140397683393056, id(Decimal): 140397688486432

If I check the module which both `type(lineitem.quantity)` and `Decimal` comes 
from, I get the same module/file:
    `inspect.getmodule(type(lineitem.quantity))`
         <module 'decimal' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py'>
    `inspect.getmodule(Decimal)`
         <module 'decimal' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py'>

Production App Engine and the old_devappserver.py do not exhibit this behavior, 
so it's something to do with the new dev_appserver (that came with SDK 1.7.6), 
maybe withinin sandbox.py -> BaseImportHook (http://goo.gl/0WcH0)?

What version of the product are you using? On what operating system?
Python 2.7
App Engine SDK 1.7.6
Issue on both Windows 7 and Mac 10.8.3

Original issue reported on code.google.com by techniq35 on 27 Mar 2013 at 5:36

GoogleCodeExporter commented 9 years ago
I wasn't sure whether to log this here, or /p/googleappengine since this is now 
part of the SDK as of 1.7.6, but I thought it would get less buried here.

Original comment by techniq35 on 27 Mar 2013 at 5:43