From 79d00e8b61509f5dc92b008057d9b3bb91ead3b2 Mon Sep 17 00:00:00 2001 From: Matthew Richards Date: Tue, 20 Apr 2021 11:30:55 +0000 Subject: [PATCH] #210: Remove config calls from being added as a constant - No real reason for this to happen, once the JSON is loaded, the values aren't changed until API restart and not modified elsewhere currently - It's probably a good thing the request behind ICAT_PROPERTIES actually gets called on demand in case the values get changed before the API is restarted - Ultimately, this is the cause of the issue (requiring DB_URL despite using ICAT backend) --- datagateway_api/common/constants.py | 4 ---- datagateway_api/common/icat/filters.py | 4 ++-- datagateway_api/src/api_start_utils.py | 3 +-- util/icat_db_generator.py | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/datagateway_api/common/constants.py b/datagateway_api/common/constants.py index f3b63956..a642c0b6 100644 --- a/datagateway_api/common/constants.py +++ b/datagateway_api/common/constants.py @@ -1,10 +1,6 @@ from datetime import datetime -from datagateway_api.common.config import config - class Constants: - DATABASE_URL = config.get_db_url() PYTHON_ICAT_DISTNCT_CONDITION = "!= null" - ICAT_PROPERTIES = config.get_icat_properties() TEST_MOD_CREATE_DATETIME = datetime(2000, 1, 1) diff --git a/datagateway_api/common/icat/filters.py b/datagateway_api/common/icat/filters.py index 14b986be..a1606e40 100644 --- a/datagateway_api/common/icat/filters.py +++ b/datagateway_api/common/icat/filters.py @@ -1,6 +1,6 @@ import logging -from datagateway_api.common.constants import Constants +from datagateway_api.common.config import config from datagateway_api.common.exceptions import FilterError from datagateway_api.common.filters import ( DistinctFieldFilter, @@ -163,7 +163,7 @@ def __init__(self, skip_value): super().__init__(skip_value) def apply_filter(self, query): - icat_properties = Constants.ICAT_PROPERTIES + icat_properties = config.get_icat_properties() icat_set_limit(query, self.skip_value, icat_properties["maxEntities"]) diff --git a/datagateway_api/src/api_start_utils.py b/datagateway_api/src/api_start_utils.py index c62d4020..f6c2ad0d 100644 --- a/datagateway_api/src/api_start_utils.py +++ b/datagateway_api/src/api_start_utils.py @@ -9,7 +9,6 @@ from datagateway_api.common.backends import create_backend from datagateway_api.common.config import config -from datagateway_api.common.constants import Constants from datagateway_api.common.database.helpers import db from datagateway_api.src.resources.entities.entity_endpoint import ( get_count_endpoint, @@ -67,7 +66,7 @@ def create_app_infrastructure(flask_app): backend_type = config.get_backend_type() if backend_type == "db": - flask_app.config["SQLALCHEMY_DATABASE_URI"] = Constants.DATABASE_URL + flask_app.config["SQLALCHEMY_DATABASE_URI"] = config.get_db_url() flask_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False db.init_app(flask_app) diff --git a/util/icat_db_generator.py b/util/icat_db_generator.py index 5a5268a5..ee379d17 100644 --- a/util/icat_db_generator.py +++ b/util/icat_db_generator.py @@ -9,7 +9,7 @@ from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.pool import QueuePool -from datagateway_api.common.constants import Constants +from datagateway_api.common.config import config from datagateway_api.common.database import models parser = argparse.ArgumentParser() @@ -38,7 +38,7 @@ engine = create_engine( - Constants.DATABASE_URL, poolclass=QueuePool, pool_size=100, max_overflow=0, + config.get_db_url(), poolclass=QueuePool, pool_size=100, max_overflow=0, ) session_factory = sessionmaker(engine) session = scoped_session(session_factory)()