﻿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
35167	JSONField get_db_prep_value being called with `Cast` types	Samantha Hughes	Jacob Walls	"Running django 4.2.9.

We have a customized version of the standard `JsonField` where we have overridden `from_db_value` and `get_prep_value`.

The worked in django ~4.1. Migrating to 4.2.9, the `get_prep_value` function started receiving `Cast` objects as the `value`, exploding json serializing/encryption , only during `bulk_update`.

We fixed it by overriding `get_db_prep_save to 



{{{
def get_db_prep_save(self, value, connection):
         if hasattr(value, ""as_sql""):
             return value
         return self.get_db_prep_value(value, connection=connection, prepared=False)
}}}


The jsonfield implementation does not check for `as_sql`. I'm not sure if this is intentional or not (unmodified JSONField columns don't seem to explode), possibly our implementation has messed up the jsonfield?
"	Bug	closed	Database layer (models, ORM)	4.2	Normal	fixed	JSONField	Samantha Hughes Simon Charette Krish Jacob Walls	Ready for checkin	1	0	0	0	0	0
