New issue 71 by my...@adconion.com: DecimalField doesn't round to
decimal_places when save to db with doj.backends.zxjdbc.postgresql ENGINE
http://code.google.com/p/django-jython/issues/detail?id=71
What steps will reproduce the problem?
1. Use "doj.backends.zxjdbc.postgresql" as database engine
In settings.py
DATABASES = {
'default': {
'ENGINE': 'doj.backends.zxjdbc.postgresql',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
2. Create a Django model with DecimalField
class A(models.Model):
revenue = models.DecimalField(max_digits=10, decimal_places=4)
3. Set revenue for a A record and save into database
a = A()
a.revenue = 1.234567
a.save()
What is the expected output? What do you see instead?
For revenue column in database:
- Expected output: 1.2346 (rounded to 4 decimal places)
- Actual output: 1.234567 (not rounded)
What version of the product are you using? On what operating system?
jython: 2.5.2
django-jython: 1.3.0b1
OS: Max OS X 10.5.8
Please provide any additional information below.
django / db / models / base.py (save_base method)
- Django rounds DecimalField value using field.get_db_prep_save(value) to
get value to save into db.
django / db / models / fields / __init__.py (DecimalField class)
- In get_db_prep_save() , connection.ops.value_to_db_decimal(value,
max_digits, decimal_places) is called to round value of Decimal Field.
## Use psycopg_postgres as engine
django / db / backends / postgres / operations.py (DatabaseOperations class)
- connection.ops delegates to DatabaseOperations class which uses
value_to_db_decimal() method from parent class BaseDatabaseOperations.
## Use zxjdbc as engine
django-jython / doj / backends / zxjdbc / postgresql / base.py
(DatabaseOperations class)
- connection.ops delegates to DatabaseOperations which inherit
zxJDBCOperationsMixin and PostgresqlDatabaseOperations, but it uses
value_to_db_decimal() method from zxJDBCOperationsMixin which simply just
return value without rounding.
Let me know if there is any part not clear or any wrong information.