else:
return self._get_toml_config_value(name, default=default)
+ def get_alembic_boolean_option(self, name: str) -> bool:
+ if self.file_config.has_option(self.config_ini_section, name):
+ return (
+ self.file_config.get(self.config_ini_section, name) == "true"
+ )
+ else:
+ value = self.toml_alembic_config.get(name, False)
+ if not isinstance(value, bool):
+ raise util.CommandError(
+ f"boolean value expected for TOML parameter {name!r}"
+ )
+ return value
+
def _get_toml_config_value(
self, name: str, default: Optional[Any] = None
) -> Union[None, str, list[str], dict[str, str], list[dict[str, str]]]:
{k: v % (self.toml_args) for k, v in value.items()},
)
else:
- raise util.CommandError("unsupported TOML value type")
+ raise util.CommandError(
+ f"unsupported TOML value type for key: {name!r}"
+ )
return value
@util.memoized_property
if prepend_sys_path:
sys.path[:0] = prepend_sys_path
- rvl = (
- config.get_alembic_option("recursive_version_locations") == "true"
- )
+ rvl = config.get_alembic_boolean_option("recursive_version_locations")
return ScriptDirectory(
util.coerce_resource_to_filename(script_location),
file_template=config.get_alembic_option(
"file_template", _default_file_template
),
truncate_slug_length=truncate_slug_length,
- sourceless=config.get_alembic_option("sourceless") == "true",
+ sourceless=config.get_alembic_boolean_option("sourceless"),
output_encoding=config.get_alembic_option(
"output_encoding", "utf-8"
),
from sqlalchemy.testing.config import combinations
from sqlalchemy.testing.config import fixture
from sqlalchemy.testing.config import requirements as requires
+from sqlalchemy.testing.config import Variation
from sqlalchemy.testing.config import variation
from .assertions import assert_raises
--- /dev/null
+.. change::
+ :tags: bug, config
+ :tickets: 1694
+
+ Fixed issue in new ``pyproject.toml`` support where boolean values, such as
+ those used for the ``recursive_version_locations`` and ``sourceless``
+ configuration parameters, would not be accepted.
+
],
)
+ @testing.combinations(
+ "sourceless", "recursive_version_locations", argnames="paramname"
+ )
+ @testing.variation("argtype", ["true", "false", "omit", "wrongvalue"])
+ def test_bool(
+ self, pyproject_only_env, argtype: testing.Variation, paramname
+ ):
+
+ cfg = pyproject_only_env
+ with cfg._toml_file_path.open("w") as file_:
+
+ if argtype.true:
+ config_option = f"{paramname} = true"
+ elif argtype.false:
+ config_option = f"{paramname} = false"
+ elif argtype.omit:
+ config_option = ""
+ elif argtype.wrongvalue:
+ config_option = f"{paramname} = 'false'"
+ else:
+ argtype.fail()
+
+ file_.write(
+ rf"""
+
+[tool.alembic]
+script_location = "%(here)s/scripts"
+
+{config_option}
+"""
+ )
+ if "toml_alembic_config" in cfg.__dict__:
+ cfg.__dict__.pop("toml_alembic_config")
+
+ if argtype.wrongvalue:
+ with expect_raises_message(
+ util.CommandError,
+ f"boolean value expected for TOML parameter '{paramname}'",
+ ):
+ sd = ScriptDirectory.from_config(cfg)
+ else:
+ sd = ScriptDirectory.from_config(cfg)
+ eq_(getattr(sd, paramname), bool(argtype.true))
+
class StdoutOutputEncodingTest(TestBase):
def test_plain(self):