endimonan commented on code in PR #44000:
URL: https://github.com/apache/superset/pull/44000#discussion_r3959561896


##########
superset/commands/database/update.py:
##########
@@ -114,9 +121,64 @@ def run(self) -> Model:
             ).run()
         except (OAuth2RedirectError, MissingOAuth2TokenError):
             pass
+        except DatabaseConnectionFailedError:
+            if not can_skip_failed_sync:
+                raise
+            logger.warning(
+                "Skipping permission sync for database %s: connection 
unavailable "
+                "and connection settings unchanged",
+                self._model_id,
+            )
 
         return database
 
+    def _can_skip_failed_sync(self) -> bool:
+        """Check that the connection and permission identity remain 
unchanged."""
+        assert self._model
+
+        connection_fields = {
+            "database_name",  # Schema and catalog permissions include this 
name.
+            "sqlalchemy_uri",
+            "encrypted_extra",
+            "extra",
+            "server_cert",
+            "impersonate_user",
+            "ssh_tunnel",
+        }
+        for key in connection_fields & self._properties.keys():
+            incoming = self._properties[key]
+            original = getattr(self._model, key)
+            if key == "sqlalchemy_uri":
+                try:
+                    original = 
make_url_safe(self._model.sqlalchemy_uri_decrypted)
+                except Exception:
+                    # An unavailable old password store must not block repairs.
+                    return False
+                incoming = make_url_safe(incoming.strip())
+                if incoming.password == PASSWORD_MASK:
+                    incoming = incoming.set(password=original.password)
+            elif key in {"extra", "encrypted_extra"}:
+                try:
+                    original = json.loads(original or "{}")
+                    incoming = json.loads(incoming or "{}")
+                except json.JSONDecodeError:
+                    return False
+            elif key == "server_cert":
+                original = original or None
+                incoming = incoming or None
+            elif key == "ssh_tunnel" and original is not None and incoming is 
not None:
+                incoming = unmask_password_info(incoming.copy(), original)
+                incoming = {
+                    field: incoming.get(field) for field in 
original.export_fields
+                }
+                original = {
+                    field: getattr(original, field) for field in 
original.export_fields
+                }

Review Comment:
   The edit modal loads the database from GET /api/v1/database/<id>/connection, 
which sets ssh_tunnel from SSHTunnel.data with the credentials masked, not from 
the schema dump. The masked values come back in the PUT and 
unmask_password_info restores them before the comparison. 
test_update_unreachable_database[True-None-True] covers this exact round trip 
with a tunnel password and expects 200.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to