[Sqlalchemy-tickets] Issue #4089: engine_url.URL does not support passwords with overridden str (zz
Brought to you by:
zzzeek
From: Brian H. <iss...@bi...> - 2017-09-25 15:04:19
|
New issue 4089: engine_url.URL does not support passwords with overridden str https://bitbucket.org/zzzeek/sqlalchemy/issues/4089/engine_urlurl-does-not-support-passwords Brian Heineman: The engine_url.URL class makes use of the ord() function which cannot be overrridden. This is preventing the direct use of overridden str values. Here is a test case that illustrates the issue: ``` #!python from sqlalchemy.engine import url as engine_url class SecurePassword(str): # any method that can be overridden by str to retrieve the value would be acceptable def __str__(self): return 'secured_password' # The ord() function in _rfc_1738_quote() https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/engine/url.py#L247 # is preventing the direct use of overridden strings # https://stackoverflow.com/questions/1893816/how-to-override-ord-behaivour-in-python-for-str-childs if __name__ == '__main__': password = SecurePassword('password_key') db_url = { 'drivername': 'mysql', 'host': 'localhost', 'port': '3306', 'username': 'root', 'password': password, 'database': 'test' } url = engine_url.URL(**db_url) print(url) assert str(url) == 'mysql://root:secured_password@localhost:3306/test' ``` |