Skip to content

Conversation

Jibola
Copy link
Contributor

@Jibola Jibola commented Mar 23, 2025

If there exists a document that fits the query criteria but does not have most of the expected keys, it will force every subsequent document to also not render those values.

class Table(models.Model):
    brand = models.CharField(...)
    volume = models.IntegerField(...)
    # intentionally left out unit

Documents:

{
  _id: 1,
  "brand": "SPAM"
},
{
  _id: 2,
  "brand": "SPAM",
  "volume": 16,
  "unit": "oz",
  ...
}

In the above example, Table.objects.raw_aggregate([]) would yield...

SPAM_OBJECT_1.brand == "SPAM" 
SPAM_OBJECT_2.brand == "SPAM"
SPAM_OBJECT_2.volume == 16 <-- Additional DB query
SPAM_OBJECT_2.unit (AttributeError)

@Jibola Jibola marked this pull request as draft March 23, 2025 23:04
@timgraham timgraham changed the title [Bugfix]: Define new column and model instance per result Fixed QuerySet.raw_aggregate() when some documents don't contain all model fields Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant