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

TypeError: object of type 'Query' has no len() #29

Closed
harshil07 opened this issue Jan 28, 2013 · 9 comments
Closed

TypeError: object of type 'Query' has no len() #29

harshil07 opened this issue Jan 28, 2013 · 9 comments

Comments

@harshil07
Copy link

Get the following error on a offset/limit query

File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/django/db/models/query.py", line 118, in _result_iter
self._fill_cache()
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/django/db/models/query.py", line 892, in _fill_cache
self._result_cache.append(self._iter.next())
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/query.py", line 327, in iterator
self._cache_results(cache_key, results)
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/query.py", line 230, in _cache_results
cond_dnf = dnf(self)
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 107, in dnf
result = _dnf(where)
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 83, in _dnf
chilren_dnfs = filter(None, imap(_dnf, where.children))
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 83, in _dnf
chilren_dnfs = filter(None, imap(_dnf, where.children))
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 83, in _dnf
chilren_dnfs = filter(None, imap(_dnf, where.children))
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 83, in _dnf
chilren_dnfs = filter(None, imap(_dnf, where.children))
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 74, in _dnf
elif lookup == 'in' and len(value) < LONG_DISJUNCTION:
TypeError: object of type 'Query' has no len()

Suor added a commit that referenced this issue Jan 29, 2013
@Suor
Copy link
Owner

Suor commented Jan 29, 2013

It looks like you are using subquery. I created a test for it and it does not fail for me.

Please check if this test is failing for you and if it is then tell me more about your setup (django version is particularly important). If test passes then can you tweak it to fail by better representing your issue?

@Suor
Copy link
Owner

Suor commented Feb 3, 2013

At least can you post an expression causing this error?

@harshil07
Copy link
Author

sorry for the delay. looks like its happening specifically on an exclude query when accessing a variable on a relationnship i.e

UserProfile.objects.exclude(user__characteristics__email_confirmed=True)

if i do the following UserProfile.objects.exclude(Q(user__characteristics__email_confirmed=True)) then it works fine.

harshil07 added a commit to harshil07/django-cacheops that referenced this issue Feb 20, 2013
@Suor
Copy link
Owner

Suor commented Feb 21, 2013

Tried your test. It passes.

@harshil07
Copy link
Author

I know it passes on mine too :( but fails in my real app.
On Feb 21, 2013 2:57 AM, "Alexander Schepanovski" notifications@github.com
wrote:

Tried your test. It passes.


Reply to this email directly or view it on GitHubhttps://github.com//issues/29#issuecomment-13877254.

@jkeesh
Copy link

jkeesh commented Apr 12, 2013

I get the same error. It fails both on my local and live version.

"TypeError: object of type ‘Query’ has no len()"

Screen Shot 2013-04-12 at 1 08 30 AM

I am using a custom manager that includes a query with an exclude call. This happens in two places where i have similar methods. I'm still trying to debug it, currently I'm just ignoring these models.

class Thread_TutorManager(models.Manager):
    """A custom manager to get threads on the tutor dashboard."""
    def get_query_set(self):
        """Get all the threads tutors should see."""
        return super(Thread_TutorManager, self).get_query_set().filter(
            needs_answer=True
        ).exclude(
            student__userprofile__grading_priority=C.Priority.IGNORED
        ).order_by(
            '-student__userprofile__grading_priority',
            "-created"
        )

I'm not exactly sure what the issue is, but thanks for the great app! I'll keep trying to look into it...

@Suor
Copy link
Owner

Suor commented Apr 13, 2013

Can you cut a part of your application into a test? It would be very helpful, right now I don't have a clue how I can reproduce that.

@jkeesh
Copy link

jkeesh commented Apr 13, 2013

Yeah sorry about that. Not exactly sure how to do that yet, but just wanted to leave feedback. How can I structure a test that would be helpful to you but totally app independent...? 

Jeremy

On Fri, Apr 12, 2013 at 6:24 PM, Alexander Schepanovski
notifications@github.com wrote:

Can you cut a part of your application into a test? It would be very helpful, right now I don't have a clue how I can reproduce that.

Reply to this email directly or view it on GitHub:
#29 (comment)

@Suor
Copy link
Owner

Suor commented Apr 13, 2013

The way I would do that:

  1. Make a fork.
  2. Ensure I can run tests ./run_tests.py. Also install all from test_requirements.txt.
  3. Copy relevant models code here https://github.com/Suor/django-cacheops/blob/master/tests/models.py
  4. Go to https://github.com/Suor/django-cacheops/blob/master/tests/models.py and paste code causing exception to IssueTests.test_29 (Everything that is there now can be trashed)
  5. ./run_tests.py IssueTests.test_29 and see it failing. Hopefully )
  6. Cut down model and test code until error disappears and make step back.
  7. Commit changes and make a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants