Skip to content

Bug: crash when DB password contains non-alphanumeric characters #997

Description

I think this an Alembic bug; I plan to open an issue with Alembic and link it here.

Update:
Alembic Config.set_main_option() documentation actually warns about this behavior:

Note that this value is passed to ConfigParser.set, which supports variable interpolation using pyformat (e.g. %(some_value)s). A raw percent sign not part of an interpolation symbol must therefore be escaped, e.g. %%. The given value may refer to another value already in the file using the interpolation format.


Python trace:

  File "/Users/sergiym/devel/MLOS/mlos_bench/mlos_bench/storage/sql/storage.py", line 46, in __init__
    self._init_engine()
    ~~~~~~~~~~~~~~~~~^^
  File "/Users/sergiym/devel/MLOS/mlos_bench/mlos_bench/storage/sql/storage.py", line 56, in _init_engine
    self.update_schema()
    ~~~~~~~~~~~~~~~~~~^^
  File "/Users/sergiym/devel/MLOS/mlos_bench/mlos_bench/storage/sql/storage.py", line 132, in update_schema
    self._schema.update()
    ~~~~~~~~~~~~~~~~~~~^^
  File "/Users/sergiym/devel/MLOS/mlos_bench/mlos_bench/storage/sql/schema.py", line 424, in update
    alembic_cfg = self._get_alembic_cfg(conn)
  File "/Users/sergiym/devel/MLOS/mlos_bench/mlos_bench/storage/sql/schema.py", line 355, in _get_alembic_cfg
    alembic_cfg.set_main_option(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        "sqlalchemy.url",
        ^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        ),
        ^^
    )
    ^
  File "/opt/anaconda3/envs/mlos/lib/python3.13/site-packages/alembic/config.py", line 269, in set_main_option
    self.set_section_option(self.config_ini_section, name, value)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/mlos/lib/python3.13/site-packages/alembic/config.py", line 296, in set_section_option
    self.file_config.set(section, name, value)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/mlos/lib/python3.13/configparser.py", line 1236, in set
    super().set(section, option, value)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/mlos/lib/python3.13/configparser.py", line 923, in set
    value = self._interpolation.before_set(self, section, option,
                                           value)
  File "/opt/anaconda3/envs/mlos/lib/python3.13/configparser.py", line 422, in before_set
    raise ValueError("invalid interpolation syntax in %r at "
                     "position %d" % (value, tmp_value.find('%')))
ValueError: invalid interpolation syntax in 'postgresql+psycopg2://mlos:****%23********@sergiym-workid-bench.postgres.database.azure.com:5432/mlos_bench' at position 27

Note the URL postgresql+psycopg2://username:****%23********@hostname:5432/dbname in the last line (password redacted). Non-alphanumeric characters get urlencoded (e.g., # becomes %23) and conflict with python % operator string interpolation in Alembic.

The problem persists after upgrading Alembic from 1.15.2 to the most recent version 1.16.5.

Activity

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

Metadata

Metadata

Labels

bugSomething isn't workingdependenciesPull requests that update a dependency filemlos-bench

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions