#27979: Using F() to save negative integers in unsigned columns on MySQL should
raise IntegrityError rather than OperationalError
-------------------------------------+-------------------------------------
Reporter: Chris Dary | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: db, mysql, | Triage Stage: Accepted
exceptions, OperationalError |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chris Dary):
* has_patch: 0 => 1
Comment:
Cool, that works for me - I can confirm that this patch fixes my issue! I
also appreciate the comment denoting what the error message related is.
{{{#!python
In [6]: import sys
In [7]: from django.db import models
In [8]: sample = SampleModel.objects.create(num=0)
INSERT INTO `payments_samplemodel` (`num`)
VALUES (0)
Execution time: 0.006077s [Database: default]
In [9]: try:
...: sample.num = models.F('num') - 1
...: sample.save()
...: except:
...: err_type, error, traceback = sys.exc_info()
...: print("Caught Exception of type: %s" % err_type)
...: print("Error: %s" % error)
...:
UPDATE `payments_samplemodel`
SET `num` = (`payments_samplemodel`.`num` - 1)
WHERE `payments_samplemodel`.`id` = 1
Execution time: 0.007049s [Database: default]
Caught Exception of type: <class 'django.db.utils.IntegrityError'>
Error: (1690, "BIGINT UNSIGNED value is out of range in
'(`sample`.`payments_samplemodel`.`num` - 1)'")
}}}
Thanks for that, Tim. Looks good to me.
--
Ticket URL: <https://code.djangoproject.com/ticket/27979#comment:5>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.ce91eaa9960adb1b1104ffafc8a1cbe4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.