Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed QuerySet.raw_aggregate() when some documents don't contain all model fields #275

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

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