From 68a2b25f0d571ac74ecc567b70d689b3606f7f64 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 22 Jul 2017 04:42:05 -0400 Subject: [PATCH] Disable select_for_update when checking the uniqueness of a cabinet if the database backend is Oracle. GitHub issue #258. Thanks to @simeon-walker for the report. Signed-off-by: Roberto Rosario --- HISTORY.rst | 1 + mayan/apps/cabinets/models.py | 9 +++++++-- mayan/apps/cabinets/serializers.py | 9 +++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 59bee28690..876d52f3a5 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,7 @@ - Fix document page widget appearance in the document page list view. - Make document version order deterministic. - Allow total page number instrospection of encrypted PDF with non ASCII user properties. GitLab issue #411. +- Oracle database compatibility update in the cabinets app. GitHub #258. 2.6.1 (2017-07-18) ================== diff --git a/mayan/apps/cabinets/models.py b/mayan/apps/cabinets/models.py index 753ad2ec2e..20d5162a03 100644 --- a/mayan/apps/cabinets/models.py +++ b/mayan/apps/cabinets/models.py @@ -1,7 +1,7 @@ from __future__ import absolute_import, unicode_literals from django.core.exceptions import NON_FIELD_ERRORS, ValidationError -from django.db import models, transaction +from django.db import connection, models, transaction from django.urls import reverse from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ @@ -64,7 +64,12 @@ class Cabinet(MPTTModel): # https://code.djangoproject.com/ticket/1751 with transaction.atomic(): - if Cabinet.objects.select_for_update().filter(parent=self.parent, label=self.label).exists(): + if connection.vendor == 'oracle': + queryset = Cabinet.objects.filter(parent=self.parent, label=self.label) + else: + queryset = Cabinet.objects.select_for_update().filter(parent=self.parent, label=self.label) + + if queryset.exists(): params = { 'model_name': _('Cabinet'), 'field_labels': _('Parent and Label') diff --git a/mayan/apps/cabinets/serializers.py b/mayan/apps/cabinets/serializers.py index c90365509a..ced682ce2f 100644 --- a/mayan/apps/cabinets/serializers.py +++ b/mayan/apps/cabinets/serializers.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from django.db import transaction +from django.db import connection, transaction from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers @@ -129,7 +129,12 @@ class WritableCabinetSerializer(serializers.ModelSerializer): # when there is a FK in the unique_together tuple # https://code.djangoproject.com/ticket/1751 with transaction.atomic(): - if Cabinet.objects.select_for_update().filter(parent=data['parent'], label=data['label']).exists(): + if connection.vendor == 'oracle': + queryset = Cabinet.objects.filter(parent=data['parent'], label=data['label']) + else: + queryset = Cabinet.objects.select_for_update().filter(parent=data['parent'], label=data['label']) + + if queryset.exists(): params = { 'model_name': _('Cabinet'), 'field_labels': _('Parent and Label')