From 5ae2336abc50f6874e5c0df785d3dbe5016d459d Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Thu, 10 Sep 2015 16:19:54 +0300 Subject: Fix MultipleObjectsReturned exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We cannot enforce SN uniqueness so let’s just use the first match when creating order with device SN --- servo/models/order.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'servo/models') diff --git a/servo/models/order.py b/servo/models/order.py index 62333b5..d968068 100644 --- a/servo/models/order.py +++ b/servo/models/order.py @@ -268,9 +268,9 @@ class Order(models.Model): Adds device to order using serial number """ sn = sn.upper() - try: - device = Device.objects.get(sn=sn) - except Device.DoesNotExist: + device = Device.objects.filter(sn=sn).first() + + if device is None: device = Device.from_gsx(sn) device.save() -- cgit v1.2.3