Coder Social home page Coder Social logo

Strange ORM issue about django-cacheops HOT 13 CLOSED

suor avatar suor commented on August 15, 2024
Strange ORM issue

from django-cacheops.

Comments (13)

Suor avatar Suor commented on August 15, 2024

.get() referring to cacheops is ok, it's the way it works. The rest is
definitely a bug.

It would be great if you created a test for it.

from django-cacheops.

aykut avatar aykut commented on August 15, 2024

I've created a pull request for test cases.

Here is what I faced when I was creating tests. Your test_requirements installed Django 1.6 and I get the ProductReview.DoesNotExist for my second .get. However when I downgraded Django to 1.4.10 I didn't get any exception!

I hope it helps you to fix this bug.

Cheers.

from django-cacheops.

Suor avatar Suor commented on August 15, 2024

That works as expected (DoesNotExist on second get) on both Django 1.6 and 1.4.10.

Also, it's not really a test. There should be asserts there or something.

from django-cacheops.

Suor avatar Suor commented on August 15, 2024

And no .get() queries all the table. There should be something wrong with your django.

from django-cacheops.

aykut avatar aykut commented on August 15, 2024
(cacheops)Aykuts-MacBook-Air:django-cacheops aykutozat$ pip freeze
Django==1.4.10
ipdb==0.8
ipython==1.1.0
redis==2.8.0
simplejson==3.3.1
wsgiref==0.1.2
(cacheops)Aykuts-MacBook-Air:django-cacheops aykutozat$ ./run_tests.py
Creating test database for alias 'default'...
Creating test database for alias 'slave'...
.....................xxx..x...
----------------------------------------------------------------------
Ran 30 tests in 0.544s

OK (expected failures=4)
Destroying test database for alias 'default'...
Destroying test database for alias 'slave'...
(cacheops)Aykuts-MacBook-Air:django-cacheops aykutozat$ pip freeze
Django==1.6
ipdb==0.8
ipython==1.1.0
redis==2.8.0
simplejson==3.3.1
wsgiref==0.1.2
(cacheops)Aykuts-MacBook-Air:django-cacheops aykutozat$ ./run_tests.py
Creating test database for alias 'default'...
Creating test database for alias 'slave'...
...................E.xxx..x...
======================================================================
ERROR: test_62 (tests.tests.IssueTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/aykutozat/cacheops/django-cacheops/tests/tests.py", line 202, in test_62
    p2.reviews.get(status=0)  # returns the same result with p.reviews.get(status=0)
  File "/Users/aykutozat/cacheops/django-cacheops/cacheops/query.py", line 524, in get
    return self.get_queryset().inplace().get(*args, **kwargs)
  File "/Users/aykutozat/cacheops/django-cacheops/cacheops/query.py", line 416, in get
    return qs._no_monkey.get(qs, *args, **kwargs)
  File "/Users/aykutozat/cacheops/lib/python2.7/site-packages/django/db/models/query.py", line 307, in get
    self.model._meta.object_name)
DoesNotExist: ProductReview matching query does not exist.

----------------------------------------------------------------------
Ran 30 tests in 1.077s

FAILED (errors=1, expected failures=4)
Destroying test database for alias 'default'...
Destroying test database for alias 'slave'...

I don't understand what can possibly wrong with my Django? I install it with pip like you or everyone else.

from django-cacheops.

Suor avatar Suor commented on August 15, 2024

Try clearing pip download cache and then create a fresh virtualenv. I just did, everything behaves as expected.

from django-cacheops.

Suor avatar Suor commented on August 15, 2024

Also, create virtualenv without access to global packages.

from django-cacheops.

aykut avatar aykut commented on August 15, 2024

Here I created a fresh virtualenv, cloned cacheops, applied my tests. Installed your requirements without pip cache. Then uninstalled Django 1.6. Installed Django 1.4.10 from source. I still didn't get the exception.

(cacheops)Aykuts-MacBook-Air:django-cacheops aykutozat$ pip freeze
Django==1.4.10
redis==2.8.0
simplejson==3.3.1
wsgiref==0.1.2
(cacheops)Aykuts-MacBook-Air:django-cacheops aykutozat$ ./run_tests.py
Creating test database for alias 'default'...
Creating test database for alias 'slave'...
.....................xxx..x...
----------------------------------------------------------------------
Ran 30 tests in 0.542s

OK (expected failures=4)
Destroying test database for alias 'default'...
Destroying test database for alias 'slave'...

from django-cacheops.

Suor avatar Suor commented on August 15, 2024

Maybe Django source, from which you install 1.4.10 is altered.

from django-cacheops.

Suor avatar Suor commented on August 15, 2024

Try installing 1.4.9 and 1.5.0

from django-cacheops.

aykut avatar aykut commented on August 15, 2024

I still didn't get any error for 1.4.9 and 1.5.0. I even tried at one of my co-workers PC who uses ubuntu, guess what I didn't get any error again.

It is clear that there is a bug here.

from django-cacheops.

aykut avatar aykut commented on August 15, 2024

Hi Suor,

I've opened a pull request which is a fix for this issue.

And let me please tell you the problem. You set the get_queryset to get_query_set method of ManagerMixin. So this means Manager has two methods now, get_querysetand get_query_set. And whenever you call .get_querysetfrom your .getor others, it actually calls your custom method and doesn't override default get_query_set.

Therefore, you need to call .get_query_set of django's "Manager" from .get_queryset of your "ManagerMixin". And it solves the bug.

Thanks.

from django-cacheops.

Suor avatar Suor commented on August 15, 2024

Looks like my environment was dirty, sorry for that confusion. Anyway it's fixed now thanks to you.

from django-cacheops.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.