#13666: Updates with F objects on decimal fields raise MySQL warnings
------------------------------------+---------------------------------------
Reporter: KyleMac | Owner: nobody
Status: closed | Milestone:
Component: Documentation | Version: 1.2
Resolution: worksforme | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
------------------------------------+---------------------------------------
Changes (by kmtracey):
* status: new => closed
* needs_better_patch: => 0
* resolution: => worksforme
* needs_tests: => 0
* needs_docs: => 0
Comment:
You've left out specifics of your model and the exception you get, so I'm
not sure exactly what you are seeing. I don't get any warnings doing what
you describe. Given this model:
{{{
#!python
class Account(models.Model):
name = models.CharField(max_length=100)
balance = models.DecimalField(decimal_places=2, max_digits=12,
default=Decimal("0"))
def __unicode__(self):
return u'%s' % self.name
}}}
A statement similar to what you show works fine, even with debug on, and
with MySQL backend:
{{{
#!python
>>> from django.conf import settings
>>> settings.DATABASE_ENGINE
'mysql'
>>> settings.DEBUG
True
>>> from ttt.models import Account
>>> from decimal import Decimal
>>> Account.objects.create(name='z1',balance='25')
<Account: z1>
>>> Account.objects.create(name='z2',balance='25')
<Account: z2>
>>> from django.db.models import F
>>>
Account.objects.filter(name__startswith='z').update(balance=F('balance')-Decimal('5.0'))
2L
>>> Account.objects.get(name='z1').balance
Decimal("20.00")
>>> Account.objects.get(name='z2').balance
Decimal("20.00")
>>>
}}}
Nor do I see any exception when 0 rows are updated. So near as I can tell
this does work without any extra work.
--
Ticket URL: <http://code.djangoproject.com/ticket/13666#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.