#35167: JSONField get_db_prep_value being called with `Cast` types
-------------------------------------+-------------------------------------
Reporter: Samantha Hughes | Owner:
| HeejunShin
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: JSONField | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by HeejunShin):
i have a question.
maybe The bug reproduction seems to be incorrect.
i tested using 2 ways.
{{{
tests[1].json = {"test": Cast('good', output_field=CharField())}
Test.objects.bulk_update(tests_will_be_updated, fields=["json"])
}}}
{{{
tests[1].json = Cast("good", output_field=CharField())
Test.objects.bulk_update(tests_will_be_updated, fields=["json"])
}}}
first one, i got "raise TypeError(f'Object of type {o.__class__.__name__}
'TypeError: Object of type Cast is not JSON serializable" error.
but value argument type in get_db_prep_value is dict.
second one, i could not get error.
value argument type in get_db_prep_value is <class
'django.db.models.expressions.Case'>. (CASE WHEN <WhereNode: (AND:
Exact(Col(polls_test,
polls.Test.id), 2))> THEN Cast(Col(polls_test,
polls.Test.json)), ELSE Value(None)).
i thought first one is type dict, so this is wrong.
is second one wrong way that reproduce bug case?
--
Ticket URL: <
https://code.djangoproject.com/ticket/35167#comment:26>