#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>
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018fa17fdf9a-499173ea-9027-44ff-b6a1-0a6dd6ac09d1-000000%40eu-central-1.amazonses.com.