Hi, I have a django.db.models.JSONField called content holding an object that I "index" into using the syntax "content__field", where the field is a JSON number. I am trying to use this in a django.db.models.Sum, as in django.db.models.Sum("content__field"), but I get this error, which I am wondering is a known quirk:
TypeError: the JSON object must be str, bytes or bytearray, not float
This is traced back to the call to json.loads in django/db/models/fields/json.py's from_db_value. It appears (based on local modifications) that Django is passing in an already-python-native value to json.loads, which is in a try. I suspect that the subsequent except was sort of meant to handle this situation, but that only catches a json.JSONDecodeError, not a TypeError. If I change that except to a catch-all, the aggregate returns the correct value.
Is this a bug? Am I doing something wrong here?