sqlalchemy / sqlalchemy/alembic
bulk insert w/ SQL Server and no-pk table in offline mode should not render SET IDENTITY INSERT
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 375
- PR merge metrics
- No merged PRs in 30d
Description
Migrated issue, originally created by Wil Tan
In offline mode, Alembic emits IDENTITY INSERT mode control statements. However, in online mode, it does not do so.
There are a few shortcomings that trips up my use cases:
-
in offline mode, sometimes I
bulk_insertinto a table with no auto-increment key. TheSET IDENTITY INSERT <table> ONstatement will result in an error in MSSQL. -
in online mode, sometimes I do want to insert fixed primary key values for auto-increment fields, but because Alembic does not turn on IDENTITY INSERT mode, MSSQL throws an error.
Would it make sense to change the current behaviour in alembic/ddl/mssql.py such that it emits SET IDENTITY INSERT statements if the rows data contains the table._autoincrement_column, regardless of offline/online mode?
I'm happy to work on a pull request if you agree with the approach.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in alembic/ddl/mssql.py and trace how bulk_insert handles IDENTITY INSERT in offline and online modes. Compare behavior for tables without an auto-increment key and rows containing the table's autoincrement column. Done means offline mode does not emit the statement for no-PK tables, while online mode enables it when fixed identity values are inserted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100