#33647: bulk_update silently truncating values for size limited fields
-------------------------------------+-------------------------------------
     Reporter:  jerch                |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * type:  Uncategorized => Bug
 * stage:  Unreviewed => Accepted


Comment:

 I manage to reproduce, this is due to
 `requires_casted_case_in_updates=True` on the Postgres backend does a
 silent `::varchar(2)` cast on the `CASE` statement.

 {{{#!python
 diff --git a/tests/queries/test_bulk_update.py
 b/tests/queries/test_bulk_update.py
 index bc252c21c6..f7244aab72 100644
 --- a/tests/queries/test_bulk_update.py
 +++ b/tests/queries/test_bulk_update.py
 @@ -3,7 +3,7 @@
  from django.core.exceptions import FieldDoesNotExist
  from django.db.models import F
  from django.db.models.functions import Lower
 -from django.db.utils import IntegrityError
 +from django.db.utils import DataError, IntegrityError
  from django.test import TestCase, override_settings, skipUnlessDBFeature

  from .models import (
 @@ -259,6 +259,14 @@ def test_ipaddressfield(self):
                      CustomDbColumn.objects.filter(ip_address=ip), models
                  )

 +    def test_charfield_constraint(self):
 +        article = Article.objects.create(
 +            name="a" * 20, created=datetime.datetime.today()
 +        )
 +        article.name = "b" * 50
 +        with self.assertRaises(DataError):
 +            Article.objects.bulk_update([article], ["name"])
 +
      def test_datetime_field(self):
          articles = [
              Article.objects.create(name=str(i),
 created=datetime.datetime.today())
 }}}

 We'll need to find an elegant way to cast to `varchar` instead of
 `varchar(N)`

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33647#comment:1>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701802e4266de-93ecd7ce-7a6b-403e-8015-1ce1340a7007-000000%40eu-central-1.amazonses.com.

Reply via email to