From 04358a5506d1e3420711154188a6cbd1fd4093d9 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Tue, 5 Feb 2019 17:59:15 +0100 Subject: [PATCH] Fix incorrect rate query --- ereuse_devicehub/resources/device/models.py | 8 ++------ ereuse_devicehub/resources/device/views.py | 5 ++++- requirements.txt | 2 +- setup.py | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 20639680..5ef33723 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -7,7 +7,7 @@ from typing import Dict, List, Set from boltons import urlutils from citext import CIText -from ereuse_utils.naming import Naming +from ereuse_utils.naming import Naming, HID_CONVERSION_DOC from more_itertools import unique_everseen from sqlalchemy import BigInteger, Boolean, Column, Enum as DBEnum, Float, ForeignKey, Integer, \ Sequence, SmallInteger, Unicode, inspect, text @@ -57,11 +57,7 @@ class Device(Thing): from Devicehub using literal identifiers from the device, so it can re-generated *offline*. - The HID is the result of joining the type of device, S/N, - manufacturer name, and model. Devices that do not have one - of these fields cannot generate HID, thus not guaranteeing - global uniqueness. - """ + """ + HID_CONVERSION_DOC model = Column(Unicode(), check_lower('model')) model.comment = """The model or brand of the device in lower case. diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index a1822515..bbe229d6 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -51,7 +51,10 @@ class Filters(query.Query): model = query.ILike(Device.model) manufacturer = query.ILike(Device.manufacturer) serialNumber = query.ILike(Device.serial_number) - rating = query.Join(Device.id == events.Rate.device_id, RateQ) + # todo test query for rating (and possibly other filters) + rating = query.Join((Device.id == events.EventWithOneDevice.device_id) + & (events.EventWithOneDevice.id == events.Rate.id), + RateQ) tag = query.Join(Device.id == Tag.device_id, TagQ) # todo This part of the query is really slow # And forces usage of distinct, as it returns many rows diff --git a/requirements.txt b/requirements.txt index 78a46c74..aa8fb818 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ click==6.7 click-spinner==0.1.8 colorama==0.3.9 colour==0.1.5 -ereuse-utils[naming, test, session, cli]==0.4.0b19 +ereuse-utils[naming, test, session, cli]==0.4.0b20 Flask==1.0.2 Flask-Cors==3.0.6 Flask-SQLAlchemy==2.3.2 diff --git a/setup.py b/setup.py index feac2257..39d48f7f 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ setup( 'teal>=0.2.0a35', # teal always first 'click', 'click-spinner', - 'ereuse-utils[naming, test, session, cli]>=0.4b19', + 'ereuse-utils[naming, test, session, cli]>=0.4b20', 'hashids', 'marshmallow_enum', 'psycopg2-binary',