#35071: Resolve lazy objects inside dictionaries when saving JSONFields
-------------------------------------+-------------------------------------
     Reporter:  Jacob Walls          |                    Owner:  Jacob
                                     |  Walls
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 I completely agree with Claude here.

 As a matter of fact `DjangoJSONEncoder` already works perfectly for this
 use case so I don't understand why we should treat promises differently
 
[https://docs.djangoproject.com/en/5.0/ref/models/fields/#django.db.models.JSONField.encoder
 given we already document using it for such cases].

 {{{#!python
 import json
 from django.core.serializers.json import DjangoJSONEncoder
 from django.utils.translation import gettext_lazy as _

 json.dumps({"key": _("foobar")})
 # TypeError: Object of type __proxy__ is not JSON serializable
 json.dumps({"key": _("foobar")}, cls=DjangoJSONEncoder)
 >>> '{"key": "foobar"}'
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/35071#comment:12>
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/0107018cc691ab98-11e71aa8-7318-4d40-a95e-f029286f9012-000000%40eu-central-1.amazonses.com.

Reply via email to