Opened 5 years ago
Closed 5 years ago
#31469 closed New feature (duplicate)
Custom lookup ignored inside built-in aggregation.
Reported by: | Oliver Ford | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.0 |
Severity: | Normal | Keywords: | custom lookup, aggregation |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
With a 'custom lookup' such as:
@JSONField.register_lookup class JsonbArrayLength(models.Transform): output_field = models.IntegerField() lookup_name = "arraylen" function = "JSONB_ARRAY_LENGTH"
Using it as qs.annotate(num_items=models.Sum("jsonfield__arraylen"))
results in the query fragment:
SELECT SUM("model"."jsonfield") AS "num_items"
i.e. the arraylen
lookup is ignored/not done. qs.values("jsonfield__arraylen")
works as expected.
Modifying it to models.Sum(JsonbArrayLength("jsonfield"))
gives the desired result.
Change History (1)
comment:1 by , 5 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Summary: | Custom lookup ignored inside built-in aggregation → Custom lookup ignored inside built-in aggregation. |
Type: | Bug → New feature |
Note:
See TracTickets
for help on using tickets.
Aggregates doesn't respect lookups, it's not related with a custom implementation or with
JSONField
's.Duplicate of #25534.