Skip to content

Commit

Permalink
#210: Remove config calls from being added as a constant
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
MRichards99 committed Apr 20, 2021
1 parent 5d99cd3 commit 79d00e8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
4 changes: 0 additions & 4 deletions datagateway_api/common/constants.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions datagateway_api/common/icat/filters.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"])


Expand Down
3 changes: 1 addition & 2 deletions datagateway_api/src/api_start_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions util/icat_db_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)()
Expand Down

0 comments on commit 79d00e8

Please sign in to comment.