# Django ORM return non-iterable object

**URL:** <https://forum.djangoproject.com/t/django-orm-return-non-iterable-object/13455>\
**Category:** ORM\
**Created:** [April 30, 2022, 6:00am UTC](https://forum.djangoproject.com/t/django-orm-return-non-iterable-object/13455 "2022-04-30T06:00:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![debadatta-tiger-anal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/debadatta-tiger-anal/32/8325_2.png) [@debadatta-tiger-anal](https://forum.djangoproject.com/u/debadatta-tiger-anal)\
**Post date:** [April 30, 2022, 6:00am UTC](https://forum.djangoproject.com/t/django-orm-return-non-iterable-object/13455/1 "2022-04-30T06:00:24Z")

</div>

![Capture](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/1/1d20a4e581404389b22cf52a73a8bfdddffa7d19.png)

My Query is

```auto
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

```auto
<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?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 30, 2022, 10:46am UTC](https://forum.djangoproject.com/t/django-orm-return-non-iterable-object/13455/2 "2022-04-30T10:46:11Z")

</div>

- 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?

- 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?

---

<div class="post-metadata">

**Author:** ![debadatta-tiger-anal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/debadatta-tiger-anal/32/8325_2.png) [@debadatta-tiger-anal](https://forum.djangoproject.com/u/debadatta-tiger-anal)\
**Post date:** [May 2, 2022, 4:54am UTC](https://forum.djangoproject.com/t/django-orm-return-non-iterable-object/13455/3 "2022-05-02T04:54:19Z")

</div>

1. Returns means, the value I get after running the query
2. Output after running the query

```auto
<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?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 2, 2022, 11:06am UTC](https://forum.djangoproject.com/t/django-orm-return-non-iterable-object/13455/4 "2022-05-02T11:06:10Z")

</div>

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

> [@debadatta-tiger-anal](#):
>
> Returns means, the value I get after running the query

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

> [@debadatta-tiger-anal](#):
>
> Output after running the query

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

> [@debadatta-tiger-anal](#):
>
> That object is not a queryset, it has no values.

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.

---

<div class="post-metadata">

**Author:** ![debadatta-tiger-anal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/debadatta-tiger-anal/32/8325_2.png) [@debadatta-tiger-anal](https://forum.djangoproject.com/u/debadatta-tiger-anal)\
**Post date:** [May 13, 2022, 2:11pm UTC](https://forum.djangoproject.com/t/django-orm-return-non-iterable-object/13455/5 "2022-05-13T14:11:53Z")

</div>

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