sqlalchemy: `Sequence.start` incorrectly set to 1 when `minvalue` is set
Describe the bug
SQLAlchemy 1.4 will set Sequence.start
to 1
if it is None
during compile()
. This is incorrect because the sequence may have a minvalue > 1
, which is incompatible with start == 1
.
To Reproduce
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def dump(sql, *multiparams, **params):
print(sql.compile(dialect=engine.dialect))
engine = sa.create_mock_engine('postgresql://', dump)
seq = sa.Sequence("my_seq", minvalue=1001)
print(f"{seq.start=}")
seq.create(engine)
print(f"{seq.start=}")
Error
Output:
seq.start=None
CREATE SEQUENCE my_seq START WITH 1 MINVALUE 1001
seq.start=1
Running that in Postgres will give:
START value (1) cannot be less than MINVALUE (1001)
Versions
- OS: Arch Linux
- Python: 3.9.7
- SQLAlchemy: 1.4.25 (SQLAlchemy-1.4.25-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl)
- Database: PostgresSQL 13.4
- DBAPI (eg: psycopg, cx_oracle, mysqlclient): N/A
Additional context
This is a regression from 1.3. I think it is due to this code.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (13 by maintainers)
Federico Caselli has proposed a fix for this issue in the main branch:
Fix start compiling in a sequence. https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4097
Sounds reasonable to me, but I recall that @zzzeek had some pretty firm ideas about how sequences should work so Iād wait to see what the boss says. š