We should add a proper versions to related managers, e.g.
{{{#!diff
diff --git a/django/db/models/fields/related_descriptors.py
b/django/db/models/fields/related_descriptors.py
index 04c956bd1e..1cba654f06 100644
--- a/django/db/models/fields/related_descriptors.py
+++ b/django/db/models/fields/related_descriptors.py
@@ -62,6 +62,7 @@ and two directions (forward and reverse) for a total of
six combinations.
If you're looking for ``ForwardManyToManyDescriptor`` or
``ReverseManyToManyDescriptor``, use ``ManyToManyDescriptor`` instead.
"""
+from asgiref.sync import sync_to_async
from django.core.exceptions import FieldError
from django.db import (
@@ -793,6 +794,11 @@ def create_reverse_many_to_one_manager(superclass,
rel):
create.alters_data = True
+ async def acreate(self, **kwargs):
+ return await sync_to_async(self.create)(**kwargs)
+
+ acreate.alters_data = True
+
def get_or_create(self, **kwargs):
self._check_fk_val()
kwargs[self.field.name] = self.instance
@@ -1191,6 +1197,11 @@ def create_forward_many_to_many_manager(superclass,
rel, reverse):
create.alters_data = True
+ async def acreate(self, **kwargs):
+ return await sync_to_async(self.create)(**kwargs)
+
+ acreate.alters_data = True
+
def get_or_create(self, *, through_defaults=None, **kwargs):
db = router.db_for_write(self.instance.__class__,
instance=self.instance)
obj, created = super(ManyRelatedManager,
self.db_manager(db)).get_or_create(
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34139>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Jon Janzen (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:2>
Comment (by Mariusz Felisiak):
Jon, would you like to prepare a patch? (against the `main` branch.)
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:3>
* owner: nobody => Jon Janzen
* status: new => assigned
Comment:
Yeah I can take care of that. I’ll be traveling for the next 2 days then
recovering from jetlag and then back on the road again, so I just want to
set expectations that this won’t be immediate :(
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:4>
Comment (by Mariusz Felisiak):
Replying to [comment:4 Jon Janzen]:
> Yeah I can take care of that. I’ll be traveling for the next 2 days then
recovering from jetlag and then back on the road again, so I just want to
set expectations that this won’t be immediate :(
Thanks and don't worry, it's a release blocker so we have time to the end
of November.
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:5>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/16256 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:6>
Comment (by Jon Janzen):
I ended up having a longer layover than intended, so I was able to write
this up.
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:7>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:8>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:9>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:10>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"7b94847e384b1a8c05a7d4c8778958c0290bdf9a" 7b94847]:
{{{
#!CommitTicketReference repository=""
revision="7b94847e384b1a8c05a7d4c8778958c0290bdf9a"
Fixed #34139 -- Fixed acreate(), aget_or_create(), and aupdate_or_create()
methods for related managers.
Bug in 58b27e0dbb3d31ca1438790870b2b51ecdb10500.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:11>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"9fb57fcc703749269987f54f9ee1d71bd9a2dbca" 9fb57fc]:
{{{
#!CommitTicketReference repository=""
revision="9fb57fcc703749269987f54f9ee1d71bd9a2dbca"
[4.1.x] Fixed #34139 -- Fixed acreate(), aget_or_create(), and
aupdate_or_create() methods for related managers.
Bug in 58b27e0dbb3d31ca1438790870b2b51ecdb10500.
Backport of 7b94847e384b1a8c05a7d4c8778958c0290bdf9a from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34139#comment:12>