﻿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
34444	Summing through a One-to-Many relationship on the property of a JSONField fails	Clément Escolano	nobody	"Hello,

When summing through a One-to-Many relationship on the property of a JSONField, there is the following error
{{{
TypeError: the JSON object must be str, bytes or bytearray, not int
}}}

To reproduce the error, you can create a model that is linked to another model with a JSONField:

{{{
class Group(models.Model):
    name = models.TextField()

class Membership(models.Model):
    group = models.ForeignKey(Group, related_name=""memberships"")
    extra = models.JSONField()
}}}

Then create a group and a membership with an amount in the JSONField:

{{{
group = Group.objects.create(name=""Test"")
Membership.objects.create(group=group, extra={""amount"": 5})
}}}

Finally, a request is made to sum the `amount` property for every group:

{{{
groups = Group.objects.annotate(total=Sum(""memberships__extra__amount"")).all()
groups[0].total
}}}

The SQL query is correct and returns the right information but accessing the data raises the error

{{{
TypeError: the JSON object must be str, bytes or bytearray, not int
}}}"	Bug	new	Database layer (models, ORM)	4.1	Normal				Unreviewed	0	0	0	0	0	0
