fix: Test connection before starting on create transaction (#15100)
* test connection before starting on create transaction * Update create.py
This commit is contained in:
parent
82ad053e50
commit
143a1b0650
|
|
@ -44,20 +44,21 @@ class CreateDatabaseCommand(BaseCommand):
|
|||
|
||||
def run(self) -> Model:
|
||||
self.validate()
|
||||
|
||||
try:
|
||||
# Test connection before starting create transaction
|
||||
TestConnectionDatabaseCommand(self._actor, self._properties).run()
|
||||
except Exception as ex: # pylint: disable=broad-except
|
||||
event_logger.log_with_context(
|
||||
action=f"db_creation_failed.{ex.__class__.__name__}",
|
||||
engine=self._properties.get("sqlalchemy_uri", "").split(":")[0],
|
||||
)
|
||||
raise DatabaseConnectionFailedError()
|
||||
|
||||
try:
|
||||
database = DatabaseDAO.create(self._properties, commit=False)
|
||||
database.set_sqlalchemy_uri(database.sqlalchemy_uri)
|
||||
|
||||
try:
|
||||
TestConnectionDatabaseCommand(self._actor, self._properties).run()
|
||||
except Exception as ex: # pylint: disable=broad-except
|
||||
db.session.rollback()
|
||||
event_logger.log_with_context(
|
||||
action=f"db_creation_failed.{ex.__class__.__name__}",
|
||||
engine=database.db_engine_spec.__name__,
|
||||
)
|
||||
raise DatabaseConnectionFailedError()
|
||||
|
||||
# adding a new database we always want to force refresh schema list
|
||||
schemas = database.get_all_schema_names(cache=False)
|
||||
for schema in schemas:
|
||||
|
|
@ -67,6 +68,7 @@ class CreateDatabaseCommand(BaseCommand):
|
|||
security_manager.add_permission_view_menu("database_access", database.perm)
|
||||
db.session.commit()
|
||||
except DAOCreateFailedError as ex:
|
||||
db.session.rollback()
|
||||
event_logger.log_with_context(
|
||||
action=f"db_creation_failed.{ex.__class__.__name__}",
|
||||
engine=database.db_engine_spec.__name__,
|
||||
|
|
|
|||
Loading…
Reference in New Issue