Skip to content

get_x_argument(as_dictionary=True) fails if x values doesn't have = #1369

@iurisilvio

Description

@iurisilvio

Describe the bug

It is not safe to use get_x_argument(as_dictionary=True) because it fails with -x foo.

Expected behavior

I'd expect an empty string "" (or True? or None?) as value instead of breaking my script.

To Reproduce

from unittest.mock import Mock

from alembic.config import Config
from alembic.runtime.environment import EnvironmentContext
from alembic.script import ScriptDirectory

context = EnvironmentContext(Config(cmd_opts=Mock(x="foo")), ScriptDirectory("."))
context.get_x_argument(as_dictionary=True)

Error

$ python example.py
Traceback (most recent call last):
  File "example.py", line 8, in <module>
    context.get_x_argument(as_dictionary=True)
  File "alembic/runtime/environment.py", line 331, in get_x_argument
    value = dict(arg.split("=", 1) for arg in value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: dictionary update sequence element #0 has length 1; 2 is required

Versions.

  • OS:
  • Python:
  • Alembic:
  • SQLAlchemy:
  • Database:
  • DBAPI:

Additional context

Have a nice day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions