﻿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 and bulk_create silently truncating values for size limited fields on postgres	jerch	Rowan Douglas	"EDIT: This issue originally only affected `bulk_update`, then started affecting `bulk_create` in Django 5.2, but that aspect was fixed in Django 5.2.10 and Django 6.0.1.

Original report follows:

----

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."	Bug	assigned	Database layer (models, ORM)	4.0	Normal			Simon Charette Lily Rowan Douglas	Accepted	0	0	0	0	0	0
