3liz / qgis-pgmetadata-plugin

QGIS Plugin to manage some metadata from PostgreSQL layer
GNU General Public License v2.0
12 stars 10 forks source link

Error “The global variable pgmetadata_connection_names is not correct.” if database connection renamed or no longer exists #119

Closed effjot closed 2 years ago

effjot commented 2 years ago

When a database connection is renamed or removed, PgMetadata’s connection_names setting is no longer up to date and CRITICAL messages about connection_names no being correct are logged. Maybe the message could be more detailed about what is wrong and suggest to fix the datasources in the processing tool.

Also, it doesn’t seem critical, because PgMetadata works alright with the remaining, reachable databases.

Should we check at startup if there are stale connection names and show a message box to the user?

I’ve had a first look at the function connections_list() in connection_manager.py, dock.py and locator.py and would prepare a suggestion / PR.

Gustry commented 2 years ago

Between warning and critical, it's indeed depending of the context. PgMetadata plugin will work without the PgMetadata database but the locator won't return the expected result :)

I think we can't check at startup because sometimes, some DB are not reachable, when you start QGIS at home, at the office, behind a VPN etc ... But the DB is still valid on another network.

Maybe the processing tool to set databases can be more visible when there is such error ?

effjot commented 2 years ago

I just experimented with checking once at startup and showing a message where the user can choose to delete or keep the stale connection names. The message also tells the user he/she can later fix it with the Set Connections processing tool. I’ll write another message with screenshots when I’m ready.

At the moment the messages in the log are not very visible, but if you happen to look there, it looks scary to see all the “critical” messages.

effjot commented 2 years ago

I can prepare a PR with my solution: at startup (or plugin reload) a message box is displayed when connections are stale. It contains a list of the stale connections and a notice about the processing tool. The user can decide to keep the connections or delete them.

The function connections_list() shows a message bar every time a connection is not found. This is probably too much, because it appears almost every tiime you do something with the plugin. Also, the message bar call doesn’t seem to play nicely with the locator bar when typing. So I suggest to leave it out. The message box at startup and the “critical” log messages should be enough IMHO.