#34523: update_or_create not work in parallel insertion
-------------------------------------+-------------------------------------
Reporter: gatello-s | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 4.2
layer (models, ORM) | Keywords: update_or_create
Severity: Normal | TransactionManagementError
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I am tests on mariadb 10.5.19 (myisam).
This test work fine on django-3.2.16
{{{
class TransactionManagementErrorTest(TestCase):
class TestModel(models.Model):
field = models.IntegerField(null=True)
class Meta(object):
db_table = 'test_model_update_or_create'
class QuerySet(models.QuerySet):
def create(self, **kwargs):
super().create(**kwargs) # simulate parallel insertion
return super().create(**kwargs)
class TestModelManager(models.Manager.from_queryset(QuerySet)):
pass
objects = TestModelManager()
def exec_sql(self, sql):
from django.db import connections, router
db = router.db_for_write(self.TestModel)
connection = connections[db]
connection.cursor().execute(sql)
def setUp(self):
super().setUp()
self.exec_sql(
'CREATE TABLE IF NOT EXISTS `test_model_update_or_create`
(`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `field` integer NULL);'
)
def tearDown(self):
self.exec_sql(
'DROP TABLE IF EXISTS `test_model_update_or_create`;'
)
super().tearDown()
def test_update_or_create(self):
self.TestModel.objects.update_or_create(id=1, defaults={'field':
2})
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34523>
Django <https://code.djangoproject.com/>
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070187c2a095aa-ac1d84be-0a70-4ed2-a18e-12e7f0bb0e71-000000%40eu-central-1.amazonses.com.