Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-06-07 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  Akash
 Type:   |  Kumar Sen
  Cleanup/optimization   |   Status:  closed
Component:  Documentation|  Version:  dev
 Severity:  Normal   |   Resolution:  fixed
 Keywords:   | Triage Stage:  Ready for
 |  checkin
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Mariusz Felisiak ):

 In [changeset:"5f2308710b5a3d9f5f135b7ade08214f5c154ec4" 5f230871]:
 {{{
 #!CommitTicketReference repository=""
 revision="5f2308710b5a3d9f5f135b7ade08214f5c154ec4"
 Fixed #30355 -- Doc'd interaction between custom managers and
 prefetch_related().
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070188970f4560-b82b55c5-aab8-48fd-9a20-be9ca1690d66-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-06-07 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  Akash
 Type:   |  Kumar Sen
  Cleanup/optimization   |   Status:  closed
Component:  Documentation|  Version:  dev
 Severity:  Normal   |   Resolution:  fixed
 Keywords:   | Triage Stage:  Ready for
 |  checkin
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Mariusz Felisiak ):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"eb84c068ed7c2982389b8d331418e99dd9709ff7" eb84c06]:
 {{{
 #!CommitTicketReference repository=""
 revision="eb84c068ed7c2982389b8d331418e99dd9709ff7"
 [4.2.x] Fixed #30355 -- Doc'd interaction between custom managers and
 prefetch_related().

 Backport of 5f2308710b5a3d9f5f135b7ade08214f5c154ec4 from main
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701889708c4c5-6af69fbc-8274-48f1-badd-980412cff040-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-06-07 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  Akash
 Type:   |  Kumar Sen
  Cleanup/optimization   |   Status:  assigned
Component:  Documentation|  Version:  dev
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Ready for
 |  checkin
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Mariusz Felisiak):

 * type:  Bug => Cleanup/optimization
 * stage:  Accepted => Ready for checkin


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070188954366d7-3d91f74a-4fac-4148-823c-76118dbe9e62-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-06-07 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+---
 Reporter:  Kyle Mulka |Owner:  Akash Kumar Sen
 Type:  Bug|   Status:  assigned
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  1  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+---
Changes (by Akash Kumar Sen):

 * needs_better_patch:  1 => 0


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070188951834d3-6f8184c8-dd71-4f34-b5a3-02458701cbaf-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-06-07 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+---
 Reporter:  Kyle Mulka |Owner:  Akash Kumar Sen
 Type:  Bug|   Status:  assigned
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  1  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  1
Easy pickings:  0  |UI/UX:  0
---+---
Changes (by Mariusz Felisiak):

 * needs_better_patch:  0 => 1


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018894d4c621-a1114580-1022-4d29-980d-71f70c407bbd-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-06-06 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+---
 Reporter:  Kyle Mulka |Owner:  Akash Kumar Sen
 Type:  Bug|   Status:  assigned
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  1  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+---
Changes (by Akash Kumar Sen):

 * needs_better_patch:  1 => 0


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070188943e6daa-a866a05e-b17b-4557-9ea5-719a65c1f384-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-06-03 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+---
 Reporter:  Kyle Mulka |Owner:  Akash Kumar Sen
 Type:  Bug|   Status:  assigned
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  1  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  1
Easy pickings:  0  |UI/UX:  0
---+---

Comment (by Akash Kumar Sen):

 The possible explanation here is that {{{queryset}}} generated with
 {{{prefetch}}} does not modify the queryset or make a DB query when we are
 fetching the reviews, this is the sole purpose of prefetch, so if we try
 to use a {{{custom manager}}} with {{{prefetch}}} that will violate the
 purpose of using prefetch, hitting 1 extra query every time we try to
 fetch the reviews.
 I will update the docs with this explanation for better understanding
 along with the alternative way using from {{{django.db.models.Prefetch}}}.

 Attaching the testcase for better understanding: https://github.com/Akash-
 Kumar-Sen/django/blob/ticket_30355_3/tests/dummy_tests/tests.py.

 Some feedbacks willbe helpful as I still have a little confusion.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018880b09a18-cee08c95-67f7-40fb-a10c-e39b264050d4-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-06-02 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+---
 Reporter:  Kyle Mulka |Owner:  Akash Kumar Sen
 Type:  Bug|   Status:  assigned
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  1  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  1
Easy pickings:  0  |UI/UX:  0
---+---
Changes (by Mariusz Felisiak):

 * needs_better_patch:  0 => 1
 * needs_docs:  1 => 0


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701887b5e0df0-e988f64d-4907-4fb9-883a-b769da483318-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-05-26 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+---
 Reporter:  Kyle Mulka |Owner:  Akash Kumar Sen
 Type:  Bug|   Status:  assigned
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  1  |  Needs documentation:  1
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+---
Changes (by Akash Kumar Sen):

 * cc: Akash Kumar Sen (added)
 * owner:  (none) => Akash Kumar Sen
 * has_patch:  0 => 1
 * status:  new => assigned


Comment:

 For me it also seems a documentation issue, as the same results can be
 achieved by obtaining other means. Created a documentation patch
 https://github.com/django/django/pull/16900

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018858cb11ca-e4a3b746-3cf7-4949-a525-308968855812-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-04-03 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+
 Reporter:  Kyle Mulka |Owner:  Akshat verma
 Type:  Bug|   Status:  assigned
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  1
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+
Changes (by Akshat verma):

 * owner:  (none) => Akshat verma
 * status:  new => assigned


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018746d18160-ecc1881d-3d94-45af-a930-bdcbee64c027-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-04-03 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+
 Reporter:  Kyle Mulka |Owner:  Akshat verma
 Type:  Bug|   Status:  assigned
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  1  |  Needs documentation:  1
  Needs tests:  1  |  Patch needs improvement:  1
Easy pickings:  1  |UI/UX:  1
---+
Changes (by Akshat verma):

 * cc: Akshat verma (added)
 * needs_better_patch:  0 => 1
 * needs_tests:  0 => 1
 * easy:  0 => 1
 * has_patch:  0 => 1
 * ui_ux:  0 => 1


Old description:

> When using prefetch and specifying a custom manager to use for a reverse
> relation, Django doesn't filter correctly. Here's an example:
>
> {{{
> class Business(models.Model):
> name = models.CharField(max_length=255)
>
> def approved_reviews(self):
> return self.review_set(manager='approved_reviews').all()
>

> class ApprovedReviewsManager(models.Manager):
> def get_queryset(self):
> return super().get_queryset().filter(status=Review.APPROVED)
>

> class Review(models.Model):
> NEW = 1
> APPROVED = 2
> STATUS_CHOICES = (
> (NEW, 'New'),
> (APPROVED, 'Approved'),
> )
> business = models.ForeignKey(Business)
> text = models.CharField(max_length=255)
> status = models.IntegerField(choices=STATUS_CHOICES, default=NEW)
>
> objects = models.Manager()
> approved_reviews = ApprovedReviewsManager()
>

> class ApprovedReviewsTest(TestCase):
> def test_with_prefetch(self):
> business = Business()
> business.save()
>
> review = Review()
> review.business = business
> review.save()
>
> businesses =
> Business.objects.prefetch_related('review_set').all()
>
> business = businesses[0]
> approved_reviews =
> business.review_set(manager='approved_reviews').all()
>
> self.assertEqual(len(approved_reviews), 0)
> }}}
>
> The full test project is available here:
> https://github.com/mulka/django_prefetch_manager_bug/blob/master/review_site/tests.py

New description:

 When using prefetch and specifying a custom manager to use for a reverse
 relation, Django doesn't filter correctly. Here's an example:

 {{{
 class Business(models.Model):
 name = models.CharField(max_length=255)

 def approved_reviews(self):
 return self.review_set(manager='approved_reviews').all()


 class ApprovedReviewsManager(models.Manager):
 def get_queryset(self):
 return super().get_queryset().filter(status=Review.APPROVED)


 class Review(models.Model):
 NEW = 1
 APPROVED = 2
 STATUS_CHOICES = (
 (NEW, 'New'),
 (APPROVED, 'Approved'),
 )
 business = models.ForeignKey(Business)
 text = models.CharField(max_length=255)
 status = models.IntegerField(choices=STATUS_CHOICES, default=NEW)

 objects = models.Manager()
 approved_reviews = ApprovedReviewsManager()


 class ApprovedReviewsTest(TestCase):
 def test_with_prefetch(self):
 business = Business()
 business.save()

 review = Review()
 review.business = business
 review.save()

 businesses = Business.objects.prefetch_related('review_set').all()

 business = businesses[0]
 approved_reviews =
 business.review_set(manager='approved_reviews').all()

 self.assertEqual(len(approved_reviews), 0)
 }}}

 The full test project is available here:
 
https://github.com/mulka/django_prefetch_manager_bug/blob/master/review_site/tests.py


 #This implementation: by Akshat verma

 class ToppingManager(models.Manager):
 def filter_vegetarian(self):
 return self.filter(is_vegetarian=True)

 #Looks non-standard. docs look like they do a safer method of modifying
 the super-class method for this sort of lazy-eval stuff. #If I rewrite
 your method in that style, it would look like:

 class ToppingManager(models.Manager):
 def filter_vegetarian(self):
 return super(ToppingManager,
 self).get_queryset().filter(is_vegetarian=True)

 #You wouldn't strictly need the super() here, but safer to use it because
 you should know that you want to start with the #models.Manager
 get_queryset method.

--

Comment:

 #This implementation: by Akshat verma

 class ToppingManager(models.Manager):
 def filter_vegetarian(self):
 return self.filter(is_vegetarian=True)

 #Looks non-standard. docs look like they do a safer method of modifying
 the super-class method for this sort of lazy-eval stuff. #If I rewrite
 your method in that style, it would look like:

 class ToppingManager(models.Manager):
 

Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2023-04-03 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+
 Reporter:  Kyle Mulka |Owner:  Akshat verma
 Type:  Bug|   Status:  assigned
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  1
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+
Changes (by Akshat verma):

 * owner:  (none) => Akshat verma
 * status:  new => assigned


Old description:

> When using prefetch and specifying a custom manager to use for a reverse
> relation, Django doesn't filter correctly. Here's an example:
>
> {{{
> class Business(models.Model):
> name = models.CharField(max_length=255)
>
> def approved_reviews(self):
> return self.review_set(manager='approved_reviews').all()
>

> class ApprovedReviewsManager(models.Manager):
> def get_queryset(self):
> return super().get_queryset().filter(status=Review.APPROVED)
>

> class Review(models.Model):
> NEW = 1
> APPROVED = 2
> STATUS_CHOICES = (
> (NEW, 'New'),
> (APPROVED, 'Approved'),
> )
> business = models.ForeignKey(Business)
> text = models.CharField(max_length=255)
> status = models.IntegerField(choices=STATUS_CHOICES, default=NEW)
>
> objects = models.Manager()
> approved_reviews = ApprovedReviewsManager()
>

> class ApprovedReviewsTest(TestCase):
> def test_with_prefetch(self):
> business = Business()
> business.save()
>
> review = Review()
> review.business = business
> review.save()
>
> businesses =
> Business.objects.prefetch_related('review_set').all()
>
> business = businesses[0]
> approved_reviews =
> business.review_set(manager='approved_reviews').all()
>
> self.assertEqual(len(approved_reviews), 0)
> }}}
>
> The full test project is available here:
> https://github.com/mulka/django_prefetch_manager_bug/blob/master/review_site/tests.py

New description:

 When using prefetch and specifying a custom manager to use for a reverse
 relation, Django doesn't filter correctly. Here's an example:

 {{{
 class Business(models.Model):
 name = models.CharField(max_length=255)

 def approved_reviews(self):
 return self.review_set(manager='approved_reviews').all()


 class ApprovedReviewsManager(models.Manager):
 def get_queryset(self):
 return super().get_queryset().filter(status=Review.APPROVED)


 class Review(models.Model):
 NEW = 1
 APPROVED = 2
 STATUS_CHOICES = (
 (NEW, 'New'),
 (APPROVED, 'Approved'),
 )
 business = models.ForeignKey(Business)
 text = models.CharField(max_length=255)
 status = models.IntegerField(choices=STATUS_CHOICES, default=NEW)

 objects = models.Manager()
 approved_reviews = ApprovedReviewsManager()


 class ApprovedReviewsTest(TestCase):
 def test_with_prefetch(self):
 business = Business()
 business.save()

 review = Review()
 review.business = business
 review.save()

 businesses = Business.objects.prefetch_related('review_set').all()

 business = businesses[0]
 approved_reviews =
 business.review_set(manager='approved_reviews').all()

 self.assertEqual(len(approved_reviews), 0)
 }}}

 The full test project is available here:
 
https://github.com/mulka/django_prefetch_manager_bug/blob/master/review_site/tests.py

--

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018746940b7c-75489ec1-f033-458b-aaf4-a21cf952195f-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2022-06-10 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+
 Reporter:  Kyle Mulka |Owner:  (none)
 Type:  Bug|   Status:  new
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  1
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+
Changes (by Ankur Roy):

 * owner:  Ankur Roy => (none)
 * status:  assigned => new


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018150b73d1d-9d7a8d37-3bd3-4374-a153-02d9ab113a1e-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2022-06-09 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+-
 Reporter:  Kyle Mulka |Owner:  Ankur Roy
 Type:  Bug|   Status:  assigned
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  1
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+-
Changes (by Ankur Roy):

 * owner:  (none) => Ankur Roy
 * status:  new => assigned


Comment:

 I will review the documentation and add the text as Simon Charette
 described if it hasn't been added already.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701814ba9bc6b-41681f94-7990-4f74-ac2e-30fe62e16276-00%40eu-central-1.amazonses.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2021-05-05 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+
 Reporter:  Kyle Mulka |Owner:  (none)
 Type:  Bug|   Status:  new
Component:  Documentation  |  Version:  dev
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  1
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+

Comment (by saeldion):

 I'd also weigh in on the bug side. Since the prefetch can happen elsewhere
 its easy to miss. It feels weird that specifying a manager would have no
 effect at all if it's already prefetched. Maybe the prefetch cache could
 be ignored/invalidated if you pass an explicit manager?

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.9781d3e3dc15000a8c7e3913f40a838a%40djangoproject.com.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2019-06-12 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
---+
 Reporter:  Kyle Mulka |Owner:  (none)
 Type:  Bug|   Status:  new
Component:  Documentation  |  Version:  master
 Severity:  Normal |   Resolution:
 Keywords: | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  1
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+
Changes (by Simon Charette):

 * needs_docs:  0 => 1
 * component:  Database layer (models, ORM) => Documentation


Comment:

 I agree that it's more of a documentation issue as `prefetch_related` will
 use the default manager just like accessing a related manager does.

 In other words `Business.objects.prefetch_related('review_set')` will use
 the default manager just like `business.review_set.all()` does.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.910c0a292fe935f8e78105782079835f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2019-06-02 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by robinh00d):

 * owner:  robinh00d => (none)
 * status:  assigned => new


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.8a24bb806ba7be12995c0a5415207d16%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2019-05-27 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  robinh00d
 Type:  Bug  |   Status:  assigned
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by robinh00d):

 * owner:  nobody => robinh00d
 * status:  new => assigned


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.43457662c607adb8ecd23b95ef083680%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2019-05-07 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Kourt Bailey):

 * cc: Kourt Bailey (added)


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.a738d9ebcb0875a6618bdbef3e1821b6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2019-04-26 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by robinh00d):

 * status:  assigned => new
 * owner:  robinh00d => (none)


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.1df57d9bcd6f92dfe20564fe418242ff%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2019-04-21 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  robinh00d
 Type:  Bug  |   Status:  assigned
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by robinh00d):

 * owner:  nobody => robinh00d
 * status:  new => assigned


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.67404a409cd6009f63280a8cb924108e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2019-04-14 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Daniel Hepper):

 * version:  1.11 => master


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.1fd77aaff6177c4060620be0c5dcbd5f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2019-04-13 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  1.11
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Daniel Hepper):

 * stage:  Unreviewed => Accepted


Comment:

 I was about to write a patch for the docs on "Using a custom reverse
 manager" to highlight the implication of using prefetch with custom
 managers.

 But thinking about it further made me realize that the prefetch might have
 happened in a completely unrelated part of the code. As a conclusion, I'd
 consider this a bug.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.3e577da4c10b62c226afe52819ba7f55%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #30355: Specifying custom manager doesn't work with prefetch

2019-04-13 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
 Reporter:  Kyle Mulka   |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  1.11
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Daniel Hepper):

 I've reproduced this behavior with the master branch, but I don't know if
 this is actually a bug or just a case of a somewhat unintuitive API. This
 should at least be documented in the section on using a custom reverse
 manager: https://docs.djangoproject.com/en/2.2/topics/db/queries/#using-a
 -custom-reverse-manager

 A possible workaround would be to use a `django.db.models.Prefetch`
 object:

 {{{
 class ApprovedReviewsTest(TestCase):
 def test_with_prefetch(self):
 business = Business()
 business.save()

 review = Review()
 review.business = business
 review.save()

 prefetch_approved_reviews = Prefetch('review_set',
 queryset=Review.approved_reviews.all())
 businesses =
 Business.objects.prefetch_related(prefetch_approved_reviews).all()

 business = businesses[0]
 approved_reviews =
 business.review_set(manager='approved_reviews').all()

 self.assertEqual(len(approved_reviews), 0)
 }}}


 In this example, you don't even have to specify the custom manager,
 `business.review_set.all()` would give you the same result.

 The underlying issue is that there is only a single prefetched object
 cache per field, see
 
https://github.com/django/django/blob/de7f6b51b21747e19e90d9e3e04e0cdbf84e8a75/django/db/models/fields/related_descriptors.py#L607

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.d8d479fa2cd6e56a53650db26820ae8f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #30355: Specifying custom manager doesn't work with prefetch

2019-04-11 Thread Django
#30355: Specifying custom manager doesn't work with prefetch
-+-
   Reporter:  Kyle   |  Owner:  nobody
  Mulka  |
   Type:  Bug| Status:  new
  Component:  Database   |Version:  1.11
  layer (models, ORM)|
   Severity:  Normal |   Keywords:
   Triage Stage: |  Has patch:  0
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 When using prefetch and specifying a custom manager to use for a reverse
 relation, Django doesn't filter correctly. Here's an example:

 {{{
 class Business(models.Model):
 name = models.CharField(max_length=255)

 def approved_reviews(self):
 return self.review_set(manager='approved_reviews').all()


 class ApprovedReviewsManager(models.Manager):
 def get_queryset(self):
 return super().get_queryset().filter(status=Review.APPROVED)


 class Review(models.Model):
 NEW = 1
 APPROVED = 2
 STATUS_CHOICES = (
 (NEW, 'New'),
 (APPROVED, 'Approved'),
 )
 business = models.ForeignKey(Business)
 text = models.CharField(max_length=255)
 status = models.IntegerField(choices=STATUS_CHOICES, default=NEW)

 objects = models.Manager()
 approved_reviews = ApprovedReviewsManager()


 class ApprovedReviewsTest(TestCase):
 def test_with_prefetch(self):
 business = Business()
 business.save()

 review = Review()
 review.business = business
 review.save()

 businesses = Business.objects.prefetch_related('review_set').all()

 business = businesses[0]
 approved_reviews =
 business.review_set(manager='approved_reviews').all()

 self.assertEqual(len(approved_reviews), 0)
 }}}

 The full test project is available here:
 
https://github.com/mulka/django_prefetch_manager_bug/blob/master/review_site/tests.py

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.9f3069634cfb2377c628d59ccd341596%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.