Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identity based columns causing Issue when tested with MSSQL #61

Open
indiVar0508 opened this issue Dec 21, 2022 · 1 comment
Open

Identity based columns causing Issue when tested with MSSQL #61

indiVar0508 opened this issue Dec 21, 2022 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers hactoberfest hactoberfest-2023 help wanted Extra attention is needed

Comments

@indiVar0508
Copy link
Contributor

indiVar0508 commented Dec 21, 2022

When running tests by making id column Identity test starts failing when tested against MSSql DB v 2017

test case

    class Article(self.Model):
        __tablename__ = "article"
        __versioned__ = copy(self.options)

        id = sa.Column(
            sa.Integer, sa.Identity(), autoincrement=True, primary_key=True
        )
        name = sa.Column(sa.Unicode(255), nullable=False)
        content = sa.Column(sa.UnicodeText)
        description = sa.Column(sa.UnicodeText)

        # Dynamic column cotaining all text content data
        fulltext_content = column_property(name + content + description)

#### Testcase flow that fails.
    def test_previous_for_first_version(self):
        article = self.Article()
        article.name = "Some article"
        article.content = "Some content"
        self.session.add(article)
        self.session.commit()

DDL

CREATE TABLE article_version (
        id INTEGER NOT NULL IDENTITY,
        name NVARCHAR(255) NULL,
        content NVARCHAR(max) NULL,
        description NVARCHAR(max) NULL,
        transaction_id BIGINT NOT NULL,
        operation_type SMALLINT NOT NULL,
        PRIMARY KEY (id, transaction_id)
)
sqlalchemy.exc.OperationalError: (pymssql._pymssql.OperationalError) (544, b"Cannot insert explicit value for identity column in table 'article_version' when IDENTITY_INSERT is set to OFF.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n")
E   [SQL: INSERT INTO article_version (id, name, content, description, transaction_id, operation_type) VALUES (%(id)s, %(name)s, %(content)s, %(description)s, %(transaction_id)s, %(operation_type)s)]
@indiVar0508
Copy link
Contributor Author

after some hit and try and feedbacks able to make it work by setting

column_copy.identity = None

in table_builder. reflect_Column method but some corner case test is failing where a related object has Identity column,
test case tests/inheritance/test_join_table_inheritance.py::TestDeepJoinedTableInheritance::test_insert

error:

E   sqlalchemy.exc.OperationalError: (pymssql._pymssql.OperationalError) (544, b"Cannot insert explicit value for identity column in table 'content' when IDENTITY_INSERT is set to OFF.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n")
E   [SQL: INSERT INTO content (id, description) VALUES (%(id)s, %(description)s)]
E   [parameters: {'id': 1, 'description': None}]
E   (Background on this error at: https://sqlalche.me/e/14/e3q8)

@indiVar0508 indiVar0508 added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers hactoberfest hactoberfest-2023 help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant