Skip to content

URL.render_as_string() generates incorrectly-escaped URL due to _sqla_url_quote #10738

@puilp0502

Description

@puilp0502

Describe the bug

The sqlalchemy.URL.render_as_string() method does not escape '%' signs, resulting in a broken URL that cannot be re-parsed by SQLAlchemy.

Optional link from https://docs.sqlalchemy.org which documents the behavior that is expected

No response

SQLAlchemy Version in Use

2.0.23

DBAPI (i.e. the database driver)

psycopg2

Database Vendor and Major Version

PostgreSQL 15

Python Version

3.10

Operating system

MacOS

To Reproduce

from sqlalchemy.engine import make_url
from sqlalchemy import URL

url = URL.create(drivername="postgres", username="a", password="a%7db", host="localhost")
recreated = make_url(url.render_as_string(hide_password=False))
assert url.password == recreated.password, f"{url.password} != {recreated.password}"

Error

Python 3.10.13 (main, Nov  6 2023, 23:53:04) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from sqlalchemy.engine import make_url
>>> from sqlalchemy import URL
>>> url = URL.create(drivername="postgres", username="a", password="a%7db", host="localhost")
>>> recreated = make_url(url.render_as_string(hide_password=False))
>>> assert url.password == recreated.password, f"{url.password} != {recreated.password}"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError: a%7db != a}b
>>> 

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existslaw of twosthe law that issues about a particular topic come in twos

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions