Skip to content

Connection to Postgres fails when password contains special characters #4393

Closed

Description

@job-almekinders

With the release of this PR, this method was added to construct the connection string for the connection to Postgres with psycopg3.

However, when a password contains special characters, they are not properly escaped, which leads to connection errors.

Expected Behavior

The special characters are escaped properly.

Current Behavior

The special characters are not escaped properly, leading to connection errors.

Steps to reproduce

In the setup file for the postgres integration tests, update all occurrences of the password test to something like test% or test!#$%&()*+,-./:;<=>?@[\]^_{|}~±`.

Then run all postgres online store integration tests by running:

make test-python-universal-postgres-online

Specifications

Version: 0.36.0
Platform: MacOS - M1
Subsystem: Sonoma 14.1.1

Possible Solution

The potential solution is to use update these lines of code to the following:

from psycopg.conninfo import make_conninfo

def _get_conninfo(config: PostgreSQLConfig) -> str:
    """Get the `conninfo` argument required for connection objects."""
    psycopg_config = {
        "user": config.user,
        "password": config.password,
        "host": config.host,
        "port": int(config.port),
        "dbname": config.database,
    }
    return make_conninfo(**psycopg_config)

Instead of using a connection string, this passes the config in key-value pairs. When passing it as key-value pairs the special characters are escaped properly.

More info here.

Activity

  1. job-almekinders commented on Aug 8, 2024

    @job-almekinders
    ContributorAuthor

    I'll probably be able to create a PR today or tomorrow for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions