Django ORM return non-iterable object

My Query is

WeeklyStrMst.objects.filter(Manufacturer__startswith='MARS', StoreClassification=channel, Category__in=cbu_lvl1_categories, SeasonalPackaging__in=seasonal_categories, Consumption__in=cbu_lvl2_categories,
                                                                                  PackType__in=pack_lvl_categories, Week__in=consideryearweeks, StoreId__in=stores).values('Year',
                                                                                                                                                       'Week', 'StoreClassification', 'StoreId').annotate(POS=Sum(target_variable), Volume=Sum('Volume'))

Here stores contain 6000-30000 values which are non-null, integer, so when I execute this, it returns me

<django.db.models.query.QuerySet object at 0x0000024FD4EAAAF0>

I have tested with less than 2000 values it works fine. What could be possible reason and workaround for this scenario?

  • What do you mean it “returns” that?
    • Are you just looking at this in the shell?
    • Output of a print statement?

Personally, I tend not to get too worried about the visual representation of an object. What you see as the result of a print statement isn’t necessarily the most useful representation of that object.

  • If you try to process that object as a queryset, what happens?

    • Do you get an error message?
    • Does your processing work any different?
  • What database engine are you using?

  • Also, what is “target_variable” in that query?
    Since it’s not in quotes, that would be a reference to a local variable. Is that supposed to be a reference to a field in your model?

  1. Returns means, the value I get after running the query
  2. Output after running the query
<django.db.models.query.QuerySet object at 0x0000024FD4EAAAF0>
  1. That object is not a queryset, it has no values.

  2. Database engine → mssql

  3. target_variable contains string value → “POS”

New findings->
After researching a lot I found that hard limit of usual 999 or 2000 value set for databases, any idea how to bypass that limit?

That must be something in the mssql engine then, because that definitely does not occur with either PostgreSQL or SQLite.

But how are you running it? Is this from the shell or from within a view?

How are you getting this output? From a print function or what the shell displays?

That output implies that the return value is a QuerySet object. It’s certainly worth further investigation.

If you’re not currently using the shell, that would be my first suggestion. Look at that object to see exactly what it is and what it contains. In the absence of finding any specific documentation to answer your question, evaluating what you have appears to be the next best option.

Solved it, Had to update the mssql-django library.