Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exceptions on no service file found #943

Merged
merged 7 commits into from
Jul 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions QgisModelBaker/gui/panel/pg_config_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ def __init__(self, parent, db_action_type):

# Fill pg_services combo box
self.pg_service_combo_box.addItem(self.tr("None"), None)
for service in pgserviceparser.service_names():
self.pg_service_combo_box.addItem(service, service)
try:
for service in pgserviceparser.service_names():
self.pg_service_combo_box.addItem(service, service)
except pgserviceparser.ServiceFileNotFound:
# we don't care when no service file is found
pass

self.pg_service_combo_box.currentIndexChanged.connect(
self._pg_service_combo_box_changed
Expand Down Expand Up @@ -223,7 +227,10 @@ def get_fields(self, configuration):
@override
def set_fields(self, configuration):

if configuration.dbservice is None:
service_config = self._get_service_config(configuration.dbservice)

# if no dbservice in the configuration or one is there but the the servicefile is not available anymore
signedav marked this conversation as resolved.
Show resolved Hide resolved
if service_config is None:

indexNoService = self.pg_service_combo_box.findData(
None, PgConfigPanel._SERVICE_COMBOBOX_ROLE.DBSERVICE
Expand Down Expand Up @@ -287,8 +294,6 @@ def set_fields(self, configuration):

# Only apply stored QSettings if the
# PG service didn't have a value for them
service_config = pgserviceparser.service_config(configuration.dbservice)

if not service_config.get("host"):
self.pg_host_line_edit.setText(configuration.dbhost)

Expand Down Expand Up @@ -352,9 +357,9 @@ def _pg_service_combo_box_changed(self):
if self._current_service is None:
self._keep_custom_settings()

if service:
service_config = pgserviceparser.service_config(service)
service_config = self._get_service_config(service)

if service_config:
# QGIS cannot handle manually set hosts with service
# So it needs to have a host defined in service conf or it takes localhost
self.pg_host_line_edit.setText(service_config.get("host", "localhost"))
Expand Down Expand Up @@ -542,6 +547,24 @@ def _read_pg_schemas_task_finished(self):
if currentTextIndex > -1:
self.pg_schema_combo_box.setCurrentIndex(currentTextIndex)

def _get_service_config(self, servicename):
if not servicename:
return None

try:
# when service file found and service found
return pgserviceparser.service_config(servicename)
except pgserviceparser.ServiceFileNotFound as sfe:
logging.warning(
f"The last used service {servicename} cannot be found, since no service file {str(sfe)} available anymore."
)
return None
except pgserviceparser.ServiceNotFound:
logging.warning(
f"The last used service {servicename} cannot be found in the service file."
)
return None


class ReadPgSchemasTask(QThread):
def __init__(self, parent):
Expand Down