Closed mnieber closed 3 years ago
As a work-around people can use this stand-alone update_or_create
function that is compatible with tagulous
(but not Django)
from django.db import transaction
from django.db.models.utils import resolve_callables
def update_or_create(query_set, defaults=None, **kwargs):
"""
Look up an object with the given kwargs, updating one with defaults
if it exists, otherwise create a new one.
Return a tuple (object, created), where created is a boolean
specifying whether an object was created.
"""
defaults = defaults or {}
query_set._for_write = True
with transaction.atomic(using=query_set.db):
# Lock the row so that a concurrent update is blocked until
# update_or_create() has performed its save.
obj, created = query_set.select_for_update().get_or_create(
defaults=defaults, **kwargs
)
if created:
return obj, created
for k, v in resolve_callables(defaults):
setattr(obj, k, v)
obj.save(using=query_set.db)
return obj, False
Thanks for spotting this - should be fixed in develop now, 1.2.1 is building to pypi with the change at the moment. Do reopen if you still have issues.
(Django version 3.2.6, tagulous version 1.20)
The Django code for
update_or_create
callsget_or_create
as follows:However,
pydoc.help
says that the signature ofget_or_create
is the following:It looks like a change to the signature in Django broke tagulous.