Skip to content

SNOW-1920422: primary key has null identity key when inserting values into a table #575

@nuwanda94

Description

@nuwanda94

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

    Python 3.11.9

  2. What operating system and processor architecture are you using?

Windows-10-10.0.22631-SP0

  1. What are the component versions in the environment (pip freeze)?

asn1crypto==1.5.1
blinker==1.9.0
certifi==2024.12.14
cffi==1.17.1
charset-normalizer==3.4.1
click==8.1.8
colorama==0.4.6
cryptography==44.0.0
filelock==3.16.1
Flask==3.1.0
Flask-Login==0.6.3
Flask-SQLAlchemy==3.1.1
greenlet==3.1.1
idna==3.10
itsdangerous==2.2.0
Jinja2==3.1.5
MarkupSafe==3.0.2
numpy==2.2.1
packaging==24.2
pandas==2.2.3
platformdirs==4.3.6
pyarrow==19.0.0
pycparser==2.22
PyJWT==2.10.1
pyOpenSSL==24.3.0
python-certifi-win32==1.6.1
python-dateutil==2.9.0.post0
pytz==2024.2
requests==2.32.3
setuptools-scm==8.1.0
six==1.17.0
snowflake-connector-python==3.12.4
snowflake-sqlalchemy==1.7.3
sortedcontainers==2.4.0
SQLAlchemy==2.0.36
tomlkit==0.13.2
typing_extensions==4.12.2
tzdata==2024.2
urllib3==2.3.0
Werkzeug==3.1.3
wrapt==1.17.0

  1. What did you do?

I have the following model class of flask :

class Demo(Base):

id = Column(Integer, primary_key=True, autoincrement=True)
user_id = Column(Integer, nullable=False)
created_by = Column(Integer)
updated_by = Column(Integer)
date_added = Column(TIMESTAMP, server_default=func.current_timestamp())
updated_at = Column(TIMESTAMP, server_default=func.current_timestamp(), onupdate=func.current_timestamp())

and i created the table in snowflake using the following :

Demo.metadata.create_all(engine)

  1. What did you expect to see?

    When inserting values in the table it gives me error that Instance <Demo at 0x17d02057e50> has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values. Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.

as the id column is set as primary and autoincrement i should be able to insert the row without passing the id value but it does not seems to be happening.

when i execute the same query using the snowflake UI i am able to insert records in the table

i am unable to map the primary key column object to database i have tried passing parameters autoincrement, Indentity(1,1) but the error persists.

  1. Can you set logging to DEBUG and collect the logs?

INFO:sqlalchemy.engine.Engine:INSERT INTO "DEMO" (user_id,created_by, updated_by) VALUES (%(user_id)s, %(created_by)s, %(updated_by)s)
DEBUG:sqlalchemy.engine.Engine:Col ('number of rows inserted',)
INFO:sqlalchemy.engine.Engine:ROLLBACK
Instance <Demo at 0x1a4494f3290> has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values. Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.


<!--
If you need urgent assistance reach out to support for escalated issue processing https://community.snowflake.com/s/article/How-To-Submit-a-Support-Case-in-Snowflake-Lodge
-->

Metadata

Metadata

Labels

bugSomething isn't workingstatus-information_neededAdditional information is required from the reporterstatus-triageIssue is under initial triage

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions