dpgaspar commented on a change in pull request #8047: [database] Improve connection URI validation URL: https://github.com/apache/incubator-superset/pull/8047#discussion_r316727411
########## File path: superset/views/database/__init__.py ########## @@ -16,17 +16,38 @@ # under the License. # pylint: disable=C,R,W import inspect +from typing import Type -from flask import Markup +from flask import current_app, Markup from flask_babel import lazy_gettext as _ +from marshmallow import ValidationError from sqlalchemy import MetaData +from sqlalchemy.engine.url import make_url +from sqlalchemy.exc import ArgumentError from superset import security_manager from superset.exceptions import SupersetException from superset.utils import core as utils from superset.views.base import SupersetFilter +def sqlalchemy_uri_validator( + uri: str, exception: Type[ValidationError] = ValidationError +) -> None: + """ + Check if a user has submitted a valid SQLAlchemy URI + """ + try: + url = make_url(uri.strip()) + except ArgumentError: + raise exception(_("Invalid connnection string could not parse rfc1738 URL")) Review comment: Updated ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org