Skip to content

Commit

Permalink
Merge pull request #53 from alexanderrichards/API_natives
Browse files Browse the repository at this point in the history
Make parameters to SQLAlchemy "native".
  • Loading branch information
alexanderrichards authored Jul 16, 2019
2 parents c8977fb + dcfe820 commit f5e2e05
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
9 changes: 5 additions & 4 deletions productionsystem/sql/models/DiracJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import json

from future.utils import native
import cherrypy
from sqlalchemy import Column, TEXT, Integer, Enum, ForeignKey, ForeignKeyConstraint
from sqlalchemy.orm import relationship
Expand Down Expand Up @@ -42,31 +43,31 @@ def get(cls, diracjob_id=None, request_id=None, parametricjob_id=None, user_id=N
"""Get dirac jobs."""
if diracjob_id is not None:
try:
diracjob_id = int(diracjob_id)
diracjob_id = native(int(diracjob_id))
except ValueError:
cls.logger.error("Dirac job id: %r should be of type int "
"(or convertable to int)", diracjob_id)
raise

if parametricjob_id is not None:
try:
parametricjob_id = int(parametricjob_id)
parametricjob_id = native(int(parametricjob_id))
except ValueError:
cls.logger.error("Parametric job id: %r should be of type int "
"(or convertable to int)", parametricjob_id)
raise

if request_id is not None:
try:
request_id = int(request_id)
request_id = native(int(request_id))
except ValueError:
cls.logger.error("Request id: %r should be of type int "
"(or convertable to int)", request_id)
raise

if user_id is not None:
try:
user_id = int(user_id)
user_id = native(int(user_id))
except ValueError:
cls.logger.error("User id: %r should be of type int "
"(or convertable to int)", user_id)
Expand Down
7 changes: 4 additions & 3 deletions productionsystem/sql/models/ParametricJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from tempfile import NamedTemporaryFile
from operator import attrgetter

from future.utils import native
import cherrypy
from sqlalchemy import (Column, SmallInteger, Integer, Boolean, TEXT, TIMESTAMP,
ForeignKey, Enum, CheckConstraint, event, inspect)
Expand Down Expand Up @@ -281,23 +282,23 @@ def get(cls, request_id=None, parametricjob_id=None, user_id=None):
"""Get parametric jobs."""
if request_id is not None:
try:
request_id = int(request_id)
request_id = native(int(request_id))
except ValueError:
cls.logger.error("Request id: %r should be of type int "
"(or convertable to int)", request_id)
raise

if parametricjob_id is not None:
try:
parametricjob_id = int(parametricjob_id)
parametricjob_id = native(int(parametricjob_id))
except ValueError:
cls.logger.error("Parametric job id: %r should be of type int "
"(or convertable to int)", parametricjob_id)
raise

if user_id is not None:
try:
user_id = int(user_id)
user_id = native(int(user_id))
except ValueError:
cls.logger.error("User id: %r should be of type int "
"(or convertable to int)", user_id)
Expand Down
9 changes: 5 additions & 4 deletions productionsystem/sql/models/Requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from datetime import datetime
from operator import attrgetter

from future.utils import native
import cherrypy
from sqlalchemy import Column, Integer, TIMESTAMP, TEXT, ForeignKey, Enum, event, inspect
from sqlalchemy.exc import SQLAlchemyError
Expand Down Expand Up @@ -120,7 +121,7 @@ def monitor(self):
def delete(cls, request_id):
"""Delete a requests from the DB."""
try:
request_id = int(request_id)
request_id = native(int(request_id))
except ValueError:
cls.logger.error("Request id: %r should be of type int "
"(or convertable to int)", request_id)
Expand All @@ -145,17 +146,17 @@ def get(cls, request_id=None, user_id=None,
if request_id is not None:
try:
if isinstance(request_id, (list, tuple)):
request_id = [int(i) for i in request_id]
request_id = [native(int(i)) for i in request_id]
else:
request_id = int(request_id)
request_id = native(int(request_id))
except ValueError:
cls.logger.error("Request id: %r should be of type int "
"(or convertable to int)", request_id)
raise

if user_id is not None:
try:
user_id = int(user_id)
user_id = native(int(user_id))
except ValueError:
cls.logger.error("User id: %r should be of type int "
"(or convertable to int)", user_id)
Expand Down
5 changes: 3 additions & 2 deletions productionsystem/sql/models/Services.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json
import logging
from datetime import datetime
from future.utils import native, native_str
import cherrypy
from sqlalchemy import Column, Integer, String, TIMESTAMP, Enum
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
Expand Down Expand Up @@ -59,13 +60,13 @@ def get_services(cls, service_id=None, service_name=None):
"""
if service_name is not None:
if not isinstance(service_name, str):
if not isinstance(service_name, (str, native_str)):
cls.logger.error("Service name: %r should be of type str", service_name)
raise TypeError

if service_id is not None:
try:
service_id = int(service_id)
service_id = native(int(service_id))
except ValueError:
cls.logger.error("Service id: %r should be of type int "
"(or convertable to int)", service_id)
Expand Down
3 changes: 2 additions & 1 deletion productionsystem/sql/models/Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from builtins import * # pylint: disable=wildcard-import, unused-wildcard-import, redefined-builtin

import logging
from future.utils import native
import cherrypy
from distutils.util import strtobool # pylint: disable=import-error, no-name-in-module
from sqlalchemy import Column, Integer, TEXT, Boolean
Expand Down Expand Up @@ -75,7 +76,7 @@ def get_users(cls, user_id=None):
"""
if user_id is not None:
try:
user_id = int(user_id)
user_id = native(int(user_id))
except ValueError:
cls.logger.error("User id: %r should be of type int "
"(or convertable to int)", user_id)
Expand Down

0 comments on commit f5e2e05

Please sign in to comment.