Re: [Django] #33835: Select_related().only() in the Prefetch class increases the number of queries for the InverseManyToOne relation.

2022-07-08 Thread Django
#33835: Select_related().only() in the Prefetch class increases the number of
queries for the InverseManyToOne relation.
-+-
 Reporter:  Ipakeev  |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  dev
  (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
-+-
Changes (by Ipakeev):

 * Attachment "PR2.PNG" 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070181df4f5002-9092d67d-9e1c-42f3-a204-0f7a35643336-00%40eu-central-1.amazonses.com.


Re: [Django] #33835: Select_related().only() in the Prefetch class increases the number of queries for the InverseManyToOne relation.

2022-07-08 Thread Django
#33835: Select_related().only() in the Prefetch class increases the number of
queries for the InverseManyToOne relation.
-+-
 Reporter:  Ipakeev  |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  dev
  (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
-+-
Changes (by Ipakeev):

 * Attachment "PR1.PNG" 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070181df4f35d7-cb4de853-16d9-43cd-b845-fa50dd6a0dfc-00%40eu-central-1.amazonses.com.


[Django] #33835: Select_related().only() in the Prefetch class increases the number of queries for the InverseManyToOne relation.

2022-07-08 Thread Django
#33835: Select_related().only() in the Prefetch class increases the number of
queries for the InverseManyToOne relation.
-+-
   Reporter:  Ipakeev|  Owner:  nobody
   Type:  Bug| Status:  new
  Component:  Database   |Version:  dev
  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  |
-+-
 I'm trying to optimize graphQL queries. When I use Prefetch with
 **select_related** and **only** optimizations, I encounter an increase in
 database queries. This is because I'm prefetching Book via
 InverseManyToOne relation and It needs a **publisher_id** in the **only**
 method.
 {{{
 class Author(models.Model):
 name = models.CharField(max_length=32)


 class Book(models.Model):
 title = models.CharField(max_length=32)
 author = models.ForeignKey("Author", on_delete=models.CASCADE)
 publisher = models.ForeignKey(
 "Publisher",
 on_delete=models.CASCADE,
 related_name="books",
 )


 class Publisher(models.Model):
 address = models.CharField(max_length=32)


 class AuthorType(DjangoObjectType):
 class Meta:
 model = Author


 class BookType(DjangoObjectType):
 class Meta:
 model = Book


 class PublisherType(DjangoObjectType):
 class Meta:
 model = Publisher
 }}}


 Fill in the database:
 {{{
 with transaction.atomic():
 authors = Author.objects.bulk_create([
 Author(name=f"Name{i}") for i in range(10)
 ])
 publishers = Publisher.objects.bulk_create([
 Publisher(address=f"Address{i}") for i in range(10)
 ])
 Book.objects.bulk_create([
 Book(
 title=f"Title{i}",
 author=random.choice(authors),
 publisher=random.choice(publishers),
 ) for i in range(20)
 ])
 }}}


 GraphQL query:
 {{{
 {
   publishers {
 address
 books {
   title
   author {
 name
   }
 }
   }
 }
 }}}


 22 db queries:
 {{{
 class Query(graphene.ObjectType):
 publishers = graphene.List(PublisherType)

 def resolve_publishers(self, info):
 queryset = Book.objects.select_related("author").only("title",
 "author__name")
 return Publisher.objects.prefetch_related(Prefetch("books",
 queryset)).only("address")
 }}}

 2 db queries:
 {{{
 class Query(graphene.ObjectType):
 publishers = graphene.List(PublisherType)

 def resolve_publishers(self, info):
 queryset = Book.objects.select_related("author").only("title",
 "author__name", "publisher_id")
 return Publisher.objects.prefetch_related(Prefetch("books",
 queryset)).only("address")
 }}}

 I fixed function **prefetch_related_objects** at django/db/models/query.py
 and now I don't need **publisher_id** in **only** method:
 {{{
 ...
 prefetcher, descriptor, attr_found, is_fetched = get_prefetcher(
 first_obj, through_attr, to_attr
 )

 from django.db.models.fields.related_descriptors import
 ReverseManyToOneDescriptor
 if type(descriptor) is ReverseManyToOneDescriptor:
 lookup.queryset.query.deferred_loading[0].add(descriptor.field.attname)

 if not attr_found:
 raise AttributeError(
 ...
 }}}

-- 
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/01070181df4ec14c-0553a6c8-b9aa-44f4-b755-ba62040b91c9-00%40eu-central-1.amazonses.com.


Re: [Django] #33832: Support M2M validation using signals

2022-07-08 Thread Django
#33832: Support M2M validation using signals
-+-
 Reporter:  ldeluigi |Owner:  nobody
 Type:  New feature  |   Status:  closed
Component:  contrib.admin|  Version:  4.0
 Severity:  Normal   |   Resolution:  invalid
 Keywords:  validation m2m   | Triage Stage:
  signal manytomany  |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by ldeluigi):

 If someone stumbles upon this I managed to fix my issue with this
 monkeypatch of
 
[https://github.com/django/django/blob/eb3699ea775548a22e0407ad12bf8cbdeaf95ff5/django/contrib/admin/options.py#L1748]:

 {{{
 from django.contrib.admin.options import *
 from django.contrib.admin.exceptions import DisallowedModelAdminToField
 from django.core.exceptions import (
 PermissionDenied,
 ValidationError,
 )
 from django.contrib.admin.utils import (
 flatten_fieldsets,
 unquote,
 )
 from django.forms.formsets import all_valid
 from django.contrib.admin import helpers
 from django.utils.translation import gettext as _

 class NewModelAdmin(ModelAdmin):
 def _changeform_view(self, request, object_id, form_url,
 extra_context):
 to_field = request.POST.get(TO_FIELD_VAR,
 request.GET.get(TO_FIELD_VAR))
 if to_field and not self.to_field_allowed(request, to_field):
 raise DisallowedModelAdminToField(
 "The field %s cannot be referenced." % to_field
 )

 model = self.model
 opts = model._meta

 if request.method == "POST" and "_saveasnew" in request.POST:
 object_id = None

 add = object_id is None

 if add:
 if not self.has_add_permission(request):
 raise PermissionDenied
 obj = None

 else:
 obj = self.get_object(request, unquote(object_id), to_field)

 if request.method == "POST":
 if not self.has_change_permission(request, obj):
 raise PermissionDenied
 else:
 if not self.has_view_or_change_permission(request, obj):
 raise PermissionDenied

 if obj is None:
 return self._get_obj_does_not_exist_redirect(request,
 opts, object_id)

 fieldsets = self.get_fieldsets(request, obj)
 ModelForm = self.get_form(
 request, obj, change=not add,
 fields=flatten_fieldsets(fieldsets)
 )
 if request.method == "POST":
 form = ModelForm(request.POST, request.FILES, instance=obj)
 formsets, inline_instances = self._create_formsets(
 request,
 form.instance if add else obj,
 change=not add,
 )
 form_validated = form.is_valid()
 if form_validated:
 new_object = self.save_form(request, form, change=not add)
 else:
 new_object = form.instance
 if all_valid(formsets) and form_validated:
 try:
 self.save_model(request, new_object, form, not add)
 self.save_related(request, form, formsets, not add)
 change_message = self.construct_change_message(
 request, form, formsets, add
 )
 if add:
 self.log_addition(request, new_object,
 change_message)
 return self.response_add(request, new_object)
 else:
 self.log_change(request, new_object,
 change_message)
 return self.response_change(request, new_object)
 except ValidationError as e:
 form_validated = False
 form._update_errors([e])
 else:
 form_validated = False
 else:
 if add:
 initial = self.get_changeform_initial_data(request)
 form = ModelForm(initial=initial)
 formsets, inline_instances = self._create_formsets(
 request, form.instance, change=False
 )
 else:
 form = ModelForm(instance=obj)
 formsets, inline_instances = self._create_formsets(
 request, obj, change=True
 )

 if not add and not self.has_change_permission(request, obj):
 readonly_fields = flatten_fieldsets(fieldsets)
 else:
 readonly_fields = 

Re: [Django] #33718: Drop support for MySQL 5.7.

2022-07-08 Thread Django
#33718: Drop support for MySQL 5.7.
-+-
 Reporter:  Mariusz Felisiak |Owner:  Mariusz
 Type:   |  Felisiak
  Cleanup/optimization   |   Status:  closed
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  fixed
 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 GitHub ):

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


Comment:

 In [changeset:"eb3699ea775548a22e0407ad12bf8cbdeaf95ff5" eb3699ea]:
 {{{
 #!CommitTicketReference repository=""
 revision="eb3699ea775548a22e0407ad12bf8cbdeaf95ff5"
 Fixed #33718 -- Dropped support for MySQL 5.7.
 }}}

-- 
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/01070181dd93f16d-d3ec263b-8ac7-4956-81ab-2ce6c5b9214f-00%40eu-central-1.amazonses.com.


Re: [Django] #33834: Compact way to in-place update of the ORM model instance

2022-07-08 Thread Django
#33834: Compact way to in-place update of the ORM model instance
-+-
 Reporter:  Anton Danilchenko|Owner:  nobody
 Type:  New feature  |   Status:  closed
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  duplicate
 Keywords:  orm  | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Mariusz Felisiak):

 * status:  new => closed
 * type:  Cleanup/optimization => New feature
 * resolution:   => duplicate


Comment:

 Duplicate of #3182.

-- 
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/01070181dd1887fd-483d7fc8-8a57-4c94-ad58-f0c24a979eac-00%40eu-central-1.amazonses.com.


[Django] #33834: Compact way to in-place update of the ORM model instance

2022-07-08 Thread Django
#33834: Compact way to in-place update of the ORM model instance
-+-
   Reporter:  Anton  |  Owner:  nobody
  Danilchenko|
   Type: | Status:  new
  Cleanup/optimization   |
  Component:  Database   |Version:  dev
  layer (models, ORM)|
   Severity:  Normal |   Keywords:  orm
   Triage Stage: |  Has patch:  0
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 Hello,

 I think that it will be useful to have such a methods to update the
 instance in-place, that saves a bit of typing:

 {{{
 book = Book.objects.get(pk=123)

 # Currently we do next
 book.title = "New title"
 book.year = 2022
 book.save()

 # NEW WAY: Set multiple fields in-place
 book.set(title="New title", year=2022)
 book.save()

 # NEW WAY: Update multiple fields in-place
 book.update(title="New title", year=2022)
 }}}

 This way we can save on typing, and set fields (especially if we have them
 in a dict) easily. Or we can update an object with new field values and
 save it explicitly.

 It can be implemented easily in the base Model class by adding two
 methods:

 {{{
 class Model:
 def set(self, **kwargs):
 for name, value ink wargs.items():
 setattr(name, value)

 def update(self, **kwargs):
 self.set(kwargs)
 return self.save()
 }}}

 My question is next - why it's no such obvious operations in the Django
 ORM yet? Is it done by purpose?

-- 
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/01070181dd0660ce-0c171876-ab9b-4fdf-a5be-e6c9a5d58c7e-00%40eu-central-1.amazonses.com.


Re: [Django] #33825: Stop allowing 'django.db.backends.postgresql_psycopg2' in DATABASES

2022-07-08 Thread Django
#33825: Stop allowing 'django.db.backends.postgresql_psycopg2' in DATABASES
-+-
 Reporter:  Maxim Danilov|Owner:  nobody
 Type:   |   Status:  closed
  Cleanup/optimization   |
Component:  Database layer   |  Version:  4.0
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  wontfix
 Keywords:  db.backend   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Carlton Gibson):

 Yes. Absolutely. And that would be the the deprecation path, if we decided
 to go that way.

 My point was more, I don't think this is worth the disruption at this
 stage, prior to #33308.
 (If there's a consensus to remove it then fair enough, otherwise I'd say
 let's revisit when adding Psycopg3 support.)

-- 
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/01070181dd01754f-c5df8e85-4719-4ea3-a2c5-c6835883abd8-00%40eu-central-1.amazonses.com.


Re: [Django] #33778: pyproject.toml uses the incorrect "legacy" setuptools backend and unnecessary wheel dep

2022-07-08 Thread Django
#33778: pyproject.toml uses the incorrect "legacy" setuptools backend and
unnecessary wheel dep
--+-
 Reporter:  Michał Górny  |Owner:  Adit Krishnan
 Type:  Bug   |   Status:  assigned
Component:  Packaging |  Version:  4.0
 Severity:  Normal|   Resolution:
 Keywords:| Triage Stage:  Accepted
Has patch:  0 |  Needs documentation:  0
  Needs tests:  0 |  Patch needs improvement:  0
Easy pickings:  1 |UI/UX:  0
--+-

Comment (by Adam Johnson):

 Thank you for reporting this, I've updated [https://adamj.eu/projects/ my
 maintained packages] as a result.

-- 
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/01070181dce1a400-1fb33bfc-0642-4d6d-9592-019ba7fbe8c8-00%40eu-central-1.amazonses.com.


Re: [Django] #33829: BaseConstraint.deconstruct() and __eq__ operators don't take violation_error_message into account.

2022-07-08 Thread Django
#33829: BaseConstraint.deconstruct() and __eq__ operators don't take
violation_error_message into account.
-+-
 Reporter:  Mariusz Felisiak |Owner:  Stéphane
 |  "Twidi" Angel
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  4.1
  (models, ORM)  |
 Severity:  Release blocker  |   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:"a3d35af26ab96598a38e9b16beac541ddb7f5aba" a3d35af]:
 {{{
 #!CommitTicketReference repository=""
 revision="a3d35af26ab96598a38e9b16beac541ddb7f5aba"
 [4.1.x] Fixed #33829 -- Made BaseConstraint.deconstruct() and equality
 handle violation_error_message.

 Regression in 667105877e6723c6985399803a364848891513cc.

 Backport of ccbf714ebeff51d1370789e5e487a978d0e2dbfb 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/01070181dc99bab5-3d568dc6-9954-4b01-8c62-b8506f6cbc71-00%40eu-central-1.amazonses.com.


Re: [Django] #33829: BaseConstraint.deconstruct() and __eq__ operators don't take violation_error_message into account.

2022-07-08 Thread Django
#33829: BaseConstraint.deconstruct() and __eq__ operators don't take
violation_error_message into account.
-+-
 Reporter:  Mariusz Felisiak |Owner:  Stéphane
 |  "Twidi" Angel
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  4.1
  (models, ORM)  |
 Severity:  Release blocker  |   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:"ccbf714ebeff51d1370789e5e487a978d0e2dbfb" ccbf714]:
 {{{
 #!CommitTicketReference repository=""
 revision="ccbf714ebeff51d1370789e5e487a978d0e2dbfb"
 Fixed #33829 -- Made BaseConstraint.deconstruct() and equality handle
 violation_error_message.

 Regression in 667105877e6723c6985399803a364848891513cc.
 }}}

-- 
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/01070181dc994ecd-82bba2f0-65dc-4a47-9411-3398c6d296be-00%40eu-central-1.amazonses.com.


Re: [Django] #33829: BaseConstraint.deconstruct() and __eq__ operators don't take violation_error_message into account.

2022-07-08 Thread Django
#33829: BaseConstraint.deconstruct() and __eq__ operators don't take
violation_error_message into account.
-+-
 Reporter:  Mariusz Felisiak |Owner:  Stéphane
 |  "Twidi" Angel
 Type:  Bug  |   Status:  assigned
Component:  Database layer   |  Version:  4.1
  (models, ORM)  |
 Severity:  Release blocker  |   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):

 * needs_better_patch:  1 => 0
 * needs_tests:  1 => 0
 * 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/01070181dc7a8bba-4031118a-0390-43e5-8fb9-206ff69c8024-00%40eu-central-1.amazonses.com.