#36418: bulk_update None on JSON field sets the value as "null" string in Postgresql -------------------------------------+------------------------------------- Reporter: Amit Maniar | Type: Bug Status: new | Component: Database | layer (models, ORM) Version: 5.2 | Severity: Normal Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Updating JSON field of Postgresql table to None stores "null" as a string when using bulk_update.
Model in models.py {{{ # Create model in DB class TestModel(models.Model): created_at = models.DateTimeField(null=False) label = models.CharField(max_length=64) json_row = models.JSONField(null=False) def __str__(self) -> str: return self.label }}} {{{ from django.utils import timezone # Create few records in database TestModel.objects.create(created_at=timezone.now(), label='test label 1', json_row={'key1': 'value1', 'key2': 1234}) TestModel.objects.create(created_at=timezone.now(), label='test label 2', json_row={'key1': 'value1', 'key2': 5678}) # Create a list to update the records test_list = [] test_list.append(TestModel.objects.get(id=1)) # update JSON field to None test_list[0].json_row = None # Bulk update objects in fields. TestModel.objects.bulk_update(test_list, fields=['json_row']) # Check DB records, json_row of TestModel (id=1) will be "null" (null as a string value) }}} -- Ticket URL: <https://code.djangoproject.com/ticket/36418> 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 visit https://groups.google.com/d/msgid/django-updates/010701970ba6b8f9-8b85ce35-3d32-41fa-9600-9954c827ea84-000000%40eu-central-1.amazonses.com.