diff --git a/src/layman/layer/db/table.py b/src/layman/layer/db/table.py index 40baeb05d..ae3814bee 100644 --- a/src/layman/layer/db/table.py +++ b/src/layman/layer/db/table.py @@ -1,3 +1,4 @@ +import logging from psycopg2 import sql from db import util as db_util @@ -7,6 +8,7 @@ from . import get_internal_table_name from .. import LAYER_TYPE, util as layer_util +logger = logging.getLogger(__name__) PATCH_MODE = patch_mode.DELETE_IF_DEPENDANT @@ -26,6 +28,18 @@ def get_layer_info(workspace, layername,): db_uri_str = None else: db_uri_str = table_uri.db_uri_str + try: + db_util.get_connection_pool(db_uri_str=db_uri_str,) + except BaseException: + result['db'] = { + 'schema': table_uri.schema, + 'table': table_uri.table, + 'geo_column': table_uri.geo_column, + 'external_uri': layer_util.redact_uri(table_uri.db_uri_str), + 'status': 'NOT_AVAILABLE', + 'error': 'Cannot connect to DB.', + } + return result try: rows = db_util.run_query(f""" SELECT schemaname, tablename, tableowner diff --git a/tests/dynamic_data/publications/layer_wfst/new_attribute_test.py b/tests/dynamic_data/publications/layer_wfst/new_attribute_test.py index 043e4ed58..d8172cf22 100644 --- a/tests/dynamic_data/publications/layer_wfst/new_attribute_test.py +++ b/tests/dynamic_data/publications/layer_wfst/new_attribute_test.py @@ -255,7 +255,7 @@ def test_new_attribute(self, layer: Publication, rest_args, params, parametrizat context={'keys': ['table_uri']})['_table_uri'] table_uris[layer_name] = table_uri old_db_attributes[layer_name] = db.get_all_table_column_names(table_uri.schema, table_uri.table, - uri_str=table_uri, ) + uri_str=table_uri.db_uri_str, ) for attr_name in attr_names: assert attr_name not in old_db_attributes[layer_name], \ f"old_db_attributes={old_db_attributes[layer_name]}, attr_name={attr_name}" @@ -284,7 +284,7 @@ def test_new_attribute(self, layer: Publication, rest_args, params, parametrizat for layer_name, attr_names in new_attributes: # assert that exactly all attr_names were created in DB table table_uri = table_uris[layer_name] - db_attributes = db.get_all_table_column_names(table_uri.schema, table_uri.table, uri_str=table_uri) + db_attributes = db.get_all_table_column_names(table_uri.schema, table_uri.table, uri_str=table_uri.db_uri_str) for attr_name in attr_names: assert attr_name in db_attributes, f"db_attributes={db_attributes}, attr_name={attr_name}" assert set(attr_names).union(set(old_db_attributes[layer_name])) == set(db_attributes)