﻿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
36418	"bulk_update None on JSON field sets the value as ""null"" string in Postgresql"	Amit Maniar		"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)

}}}
"	Bug	closed	Database layer (models, ORM)	5.2	Normal	invalid		Simon Charette Sage Abdullah	Unreviewed	0	0	0	0	0	0
