From d6bee33601f9cdb84c91868bab5cde7cff4fd66c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 5 Dec 2022 17:33:22 +0100 Subject: [PATCH] fix new hid in build --- ereuse_devicehub/inventory/forms.py | 2 -- ereuse_devicehub/resources/action/views/snapshot.py | 10 ++++++++-- ereuse_devicehub/resources/device/models.py | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 0769796d..8d6f0b8b 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -318,8 +318,6 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm): try: snapshot_json = schema.load(snapshot_json) response = self.build(snapshot_json) - response.device.set_hid() - response.device.binding.device.set_hid() except ValidationError as err: txt = "{}".format(err) self.errors(txt=txt) diff --git a/ereuse_devicehub/resources/action/views/snapshot.py b/ereuse_devicehub/resources/action/views/snapshot.py index b3c4d744..16a89bed 100644 --- a/ereuse_devicehub/resources/action/views/snapshot.py +++ b/ereuse_devicehub/resources/action/views/snapshot.py @@ -8,6 +8,7 @@ from uuid import UUID from flask import current_app as app from flask import g +from marshmallow import ValidationError from sqlalchemy.util import OrderedSet from ereuse_devicehub.db import db @@ -115,6 +116,13 @@ class SnapshotMixin: self.is_server_erase(snapshot) + snapshot.device.set_hid() + snapshot.device.binding.device.set_hid() + if not snapshot.device.hid: + txt = "Not exist the basic fields for to do an device. " + txt += "Please do one placeholder instead of one snapshot" + raise ValidationError(txt) + return snapshot def is_server_erase(self, snapshot): @@ -219,8 +227,6 @@ class SnapshotView(SnapshotMixin): try: self.snapshot_json = resource_def.schema.load(snapshot_json) snapshot = self.build() - snapshot.device.set_hid() - snapshot.device.binding.device.set_hid() except Exception as err: txt = "{}".format(err) self.errors(txt=txt, commit=True) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 3b8aef05..82adf8e7 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -772,6 +772,8 @@ class Device(Thing): system_uuid = '' if hasattr(self, 'system_uuid'): system_uuid = str(self.system_uuid or '') + if not system_uuid or not self.manufacturer: + return '' board = None board_serial_number = ''