Error using right numberformat in calculation / LC_NUMBER should set right way

Create issue
Issue #333 resolved
Former user created an issue

Hi, since a while I try to get satchmo running right way. The most horrible problem is, that it stores numbers in form "1234,56" not in "1234.56" into database. (Prices etc.) this results in an exception and installation becomes unusable. -> clean up.

After a while I've got it via the hack that I let run apache explicit with LANG='C' environment variable and setting explicit locale.setLocale('C'). voila. Seems working now.

Until I try to pay.

Item has a unit price of 20.00 €. Will - german site - displayed as 20,00 of course. All calculation works as expected (summary and so on), but on {{{/checkout/<paymentmethod>}}} I got the exception about wrong number format (in {{{decimal.py in _raise_error, line 2325}}}) again. Viewing into the local variables shows me, that decimal.py will get a "20,00" instead of a "20.00" again. Now I'm giving up. appended the backtrace. I think, satchmo should make clear how to work in multi-lingual environments/setup, should internal check numbers stored into database or make sure that numbers going to backend are formatted the right way. Any hints for a workaround welcome.

{{{ Environment:

Request Method: POST Request URL: http://shop.<the host path>/shop/checkout/giftcertificate/ Django Version: 0.97-pre-SVN-unknown Python Version: 2.4.1 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.comments', 'comment_utils', 'django.contrib.sessions', 'django.contrib.sitemaps', 'django.contrib.sites', 'satchmo.caching', 'satchmo.configuration', 'satchmo.shop', 'satchmo.contact', 'satchmo.product', 'satchmo.shipping', 'satchmo.payment', 'satchmo.discount', 'satchmo.giftcertificate', 'satchmo.supplier', 'satchmo.thumbnail', 'satchmo.l10n', 'satchmo.tax', 'satchmo.recentlist', 'satchmo.wishlist'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.doc.XViewMiddleware', 'satchmo.shop.SSLMiddleware.SSLRedirect', 'satchmo.recentlist.middleware.RecentProductMiddleware')

Traceback: File "/srv/www/vhosts/<the host path>/private/python/django/core/handlers/base.py" in get_response 82. response = callback(request, callback_args, callback_kwargs) File "/srv/www/vhosts/<the host path>/subdomains/shop/httpdocs/satchmo/giftcertificate/views.py" in pay_ship_info 47. template="checkout/giftcertificate/pay_ship.html") File "/srv/www/vhosts/<the host path>/subdomains/shop/httpdocs/satchmo/payment/common/views/payship.py" in base_pay_ship_info 124. results = form_handler(request, contact, working_cart, payment_module) File "/srv/www/vhosts/<the host path>/subdomains/shop/httpdocs/satchmo/giftcertificate/views.py" in giftcert_pay_ship_process_form 27. newOrder = payship.get_or_create_order(request, working_cart, contact, data)
File "/srv/www/vhosts/<the host path>/subdomains/shop/httpdocs/satchmo/payment/common/views/payship.py" in get_or_create_order 32. shipping=data['shipping'], discount=data['discount']) File "/srv/www/vhosts/<the host path>/subdomains/shop/httpdocs/satchmo/payment/common/pay_ship.py" in pay_ship_save 64. new_order_item.save() File "/srv/www/vhosts/<the host path>/subdomains/shop/httpdocs/satchmo/contact/models.py" in save 751. self.update_tax() File "/srv/www/vhosts/<the host path>/subdomains/shop/httpdocs/satchmo/contact/models.py" in update_tax 756. processor = tax.get_processor(order=self.order) File "/srv/www/vhosts/<the host path>/private/python/django/db/models/fields/related.py" in get 209. rel_obj = self.field.rel.to._default_manager.get(
params) File "/srv/www/vhosts/<the host path>/private/python/django/db/models/manager.py" in get 69. return self.get_query_set().get(
args, **kwargs) File "/srv/www/vhosts/<the host path>/private/python/django/db/models/query.py" in get 261. obj_list = list(clone) File "/srv/www/vhosts/<the host path>/private/python/django/db/models/query.py" in iter 114. return iter(self._get_data()) File "/srv/www/vhosts/<the host path>/private/python/django/db/models/query.py" in _get_data 486. self._result_cache = list(self.iterator()) File "/srv/www/vhosts/<the host path>/private/python/django/db/models/query.py" in iterator 189. cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params) File "/srv/www/vhosts/<the host path>/private/python/django/db/backends/util.py" in execute 18. return self.cursor.execute(sql, params) File "/srv/www/vhosts/<the host path>/private/python/django/db/backends/sqlite3/base.py" in execute 133. return Database.Cursor.execute(self, query, params) File "/srv/www/vhosts/<the host path>/private/python/django/db/backends/util.py" in typecast_decimal 97. return decimal.Decimal(s) File "/srv/www/vhosts/<the host path>/private/python/decimal.py" in new 614. self._sign, self._int, self._exp = context._raise_error(ConversionSyntax) File "/srv/www/vhosts/<the host path>/private/python/decimal.py" in _raise_error 2325. raise error, explanation

Exception Type: InvalidOperation at /shop/checkout/giftcertificate/ Exception Value: }}}

Reported by alwin

Comments (7)

  1. Former user Account Deleted

    This only with sqlite database, with mysql I have some other problems (exceptions about data truncated when insert into sub_total but this is another bug).

    Which test do you mean? all inside satchmo-folder or some specific?

  2. Former user Account Deleted

    This is Django bug not Satchmo's. The details are here: [http://code.djangoproject.com/ticket/6783 #6783] As a quick hack around, before someone commits a proper fix to Django's trunk would be to either check values in satchmo/payment/common/pay_ship.py right before processing them (i.e. treat them as string first and do .replace(",", ".") or with regexp) or on models level (i.e. override the save() on Order model and do the same trick with replace or regexp)

  3. Former user Account Deleted

    I ran it and I didn't see any error in database checks, no idea anymore whats going wrong with sqlite :(

  4. Former user Account Deleted

    You can run "./manage.py test" in your project directory to run the unit tests.

  5. Chris Moffitt repo owner

    What database are you using? If you switch to sqlite does this go away?

    Also, could you try running the included unit tests and see if they work properly.

  6. Log in to comment