From 7c89b12f442f899e88fce682177d2bc904aea59f Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Wed, 3 Apr 2019 18:53:37 +0200
Subject: [PATCH] Fix linting warnings

---
 app/commands.py   |  2 +-
 app/models.py     |  8 ++++----
 app/utils.py      |  1 +
 app/validators.py | 10 +++++-----
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/app/commands.py b/app/commands.py
index 4aa9756..eec4bc0 100644
--- a/app/commands.py
+++ b/app/commands.py
@@ -80,7 +80,7 @@ def register_cli(app):
             db.session.add(instance)
             try:
                 db.session.commit()
-            except sa.exc.IntegrityError as e:
+            except sa.exc.IntegrityError:
                 db.session.rollback()
                 app.logger.debug(f"{instance} already exists")
 
diff --git a/app/models.py b/app/models.py
index df0edd3..9d34663 100644
--- a/app/models.py
+++ b/app/models.py
@@ -932,7 +932,7 @@ class Network(CreatedMixin, db.Model):
         if string is None:
             return None
         if VLAN_NAME_RE.fullmatch(string) is None:
-            raise ValidationError("Vlan name shall match [A-Za-z0-9\-]{3,25}")
+            raise ValidationError(r"Vlan name shall match [A-Za-z0-9\-]{3,25}")
         return string
 
     def to_dict(self, recursive=False):
@@ -1257,7 +1257,7 @@ class Host(CreatedMixin, SearchableMixin, db.Model):
         # Force the string to lowercase
         lower_string = string.lower()
         if HOST_NAME_RE.fullmatch(lower_string) is None:
-            raise ValidationError("Host name shall match [a-z0-9\-]{2,20}")
+            raise ValidationError(r"Host name shall match [a-z0-9\-]{2,20}")
         existing_cname = Cname.query.filter_by(name=lower_string).first()
         if existing_cname:
             raise ValidationError(f"Host name matches an existing cname")
@@ -1360,7 +1360,7 @@ class Interface(CreatedMixin, db.Model):
         # Force the string to lowercase
         lower_string = string.lower()
         if HOST_NAME_RE.fullmatch(lower_string) is None:
-            raise ValidationError("Interface name shall match [a-z0-9\-]{2,20}")
+            raise ValidationError(r"Interface name shall match [a-z0-9\-]{2,20}")
         if self.host and not lower_string.startswith(self.host.name):
             raise ValidationError(
                 f"Interface name shall start with the host name '{self.host}'"
@@ -1494,7 +1494,7 @@ class Cname(CreatedMixin, db.Model):
         # Force the string to lowercase
         lower_string = string.lower()
         if HOST_NAME_RE.fullmatch(lower_string) is None:
-            raise ValidationError("cname shall match [a-z0-9\-]{2,20}")
+            raise ValidationError(r"cname shall match [a-z0-9\-]{2,20}")
         existing_interface = Interface.query.filter_by(name=lower_string).first()
         if existing_interface:
             raise ValidationError(f"cname matches an existing interface")
diff --git a/app/utils.py b/app/utils.py
index d9005a8..03e9b7a 100644
--- a/app/utils.py
+++ b/app/utils.py
@@ -155,6 +155,7 @@ def get_query(query, **kwargs):
         try:
             query = query.filter_by(**kwargs)
         except (sa.exc.InvalidRequestError, AttributeError) as e:
+            current_app.logger.warning(f"Invalid query arguments: {e}")
             raise CSEntryError("Invalid query arguments", status_code=422)
     return query
 
diff --git a/app/validators.py b/app/validators.py
index 2e7f8f4..8684941 100644
--- a/app/validators.py
+++ b/app/validators.py
@@ -14,11 +14,11 @@ import re
 import sqlalchemy as sa
 from wtforms import ValidationError, SelectField
 
-ICS_ID_RE = re.compile("[A-Z]{3}[0-9]{3}")
-HOST_NAME_RE = re.compile("^[a-z0-9\-]{2,20}$")
-VLAN_NAME_RE = re.compile("^[A-Za-z0-9\-]{3,25}$")
-MAC_ADDRESS_RE = re.compile("^(?:[0-9a-fA-F]{2}[:-]?){5}[0-9a-fA-F]{2}$")
-DEVICE_TYPE_RE = re.compile("^[A-Za-z0-9]{3,25}$")
+ICS_ID_RE = re.compile(r"[A-Z]{3}[0-9]{3}")
+HOST_NAME_RE = re.compile(r"^[a-z0-9\-]{2,20}$")
+VLAN_NAME_RE = re.compile(r"^[A-Za-z0-9\-]{3,25}$")
+MAC_ADDRESS_RE = re.compile(r"^(?:[0-9a-fA-F]{2}[:-]?){5}[0-9a-fA-F]{2}$")
+DEVICE_TYPE_RE = re.compile(r"^[A-Za-z0-9]{3,25}$")
 
 
 class NoValidateSelectField(SelectField):
-- 
GitLab