﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33647	bulk_update silently truncating values for size limited fields	jerch	nobody	"On postgres backend, `bulk_update` passes overlong values for size limited fields along without any notification/exception, instead truncating the value.

Repro:
{{{
#!div style=""font-size: 80%""
Code highlighting:
  {{{#!python
  # some model to repro
  class TestModel(models.Model):
      name = models.CharField(max_length=32)
  
  # in the shell
  >>> from bulk_test.models import TestModel
  >>> tm=TestModel(name='hello')
  >>> tm.save()
  >>> tm.name
  'hello'
  >>> tm.name='m'*100
  >>> tm.save()  # good, raises:
  ...
  django.db.utils.DataError: value too long for type character varying(32)
  
  >>> TestModel.objects.all().values('name')
  <QuerySet [{'name': 'hello'}]>
  >>> TestModel.objects.all().update(name='z'*100)  # good, raises as well:
  ...
  django.db.utils.DataError: value too long for type character varying(32)
  
  >>> TestModel.objects.all().values('name')
  <QuerySet [{'name': 'hello'}]>
  >>> TestModel.objects.bulk_update([tm], ['name'])  # not raising, instead truncating:
  1
  >>> TestModel.objects.all().values('name')
  <QuerySet [{'name': 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm'}]>
  }}}
}}}

Not sure, if this is intended/expected behavior, well it is inconsistent to `.save` or `.update`, which both raise here. I only tested postgres backend for this, it may apply to other size limiting databases as well (sqlite itself is not affected, as it does not limit values).

If this is intended, it may be a good idea to at least document the slightly different behavior, so users are aware of it, and can prepare their code to avoid silent truncation with follow-up errors. A better way prolly would fix `bulk_update` to spot value overflows and raise, but I am not sure, if thats feasible."	Uncategorized	new	Database layer (models, ORM)	4.0	Normal				Unreviewed	0	0	0	0	0	0
