diff --git a/pyproject.toml b/pyproject.toml index a9c780a6..ef8496a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,4 +78,4 @@ packages = ["src/snowflake"] [tool.sqla_testing] requirement_cls = "snowflake.sqlalchemy.requirements:Requirements" -profile_file = "tests/profiles.txt" +# profile_file = "tests/profiles.txt" diff --git a/tests/test_core.py b/tests/test_core.py index b8514112..c6f2100f 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -34,7 +34,7 @@ ) from sqlalchemy.exc import DBAPIError, NoSuchTableError from sqlalchemy.pool import NullPool -from sqlalchemy.sql import and_, not_, or_, select +from sqlalchemy.sql import and_, insert, not_, or_, select import snowflake.connector.errors import snowflake.sqlalchemy.snowdialect @@ -1422,6 +1422,11 @@ def test_special_schema_character(db_parameters, on_public_ci): def test_autoincrement(engine_testaccount): + """Snowflake does not guarantee generating sequence numbers without gaps. + + The generated numbers are not necesairly contigous. + https://docs.snowflake.com/en/user-guide/querying-sequences + """ metadata = MetaData() users = Table( "users", @@ -1431,38 +1436,39 @@ def test_autoincrement(engine_testaccount): ) try: - users.create(engine_testaccount) + metadata.create_all(engine_testaccount) with engine_testaccount.connect() as connection: + insert_stmt = insert(users) + select_stmt = select(users.c.name) + with connection.begin(): - connection.execute(users.insert(), [{"name": "sf1"}]) - assert connection.execute(select(users)).fetchall() == [(1, "sf1")] - connection.execute(users.insert(), [{"name": "sf2"}, {"name": "sf3"}]) - assert connection.execute(select(users)).fetchall() == [ - (1, "sf1"), - (2, "sf2"), - (3, "sf3"), - ] - connection.execute(users.insert(), {"name": "sf4"}) - assert connection.execute(select(users)).fetchall() == [ - (1, "sf1"), - (2, "sf2"), - (3, "sf3"), - (4, "sf4"), - ] + connection.execute(insert_stmt, ({"name": "sf1"})) + result = connection.execute(select_stmt).all() + assert result == [("sf1",)], result + + connection.execute(insert_stmt, ({"name": "sf2"}, {"name": "sf3"})) + result = connection.execute(select_stmt).all() + assert result == [("sf1",), ("sf2",), ("sf3",)], result + + connection.execute(insert_stmt, ({"name": "sf4"})) + result = connection.execute(select_stmt).all() + assert result == [("sf1",), ("sf2",), ("sf3",), ("sf4",)], result seq = Sequence("id_seq") nextid = connection.execute(seq) - connection.execute(users.insert(), [{"uid": nextid, "name": "sf5"}]) - assert connection.execute(select(users)).fetchall() == [ - (1, "sf1"), - (2, "sf2"), - (3, "sf3"), - (4, "sf4"), - (5, "sf5"), - ] + connection.execute(insert_stmt, ({"uid": nextid, "name": "sf5"})) + result = connection.execute(select_stmt).all() + assert result == [ + ("sf1",), + ("sf2",), + ("sf3",), + ("sf4",), + ("sf5",), + ], result + finally: - users.drop(engine_testaccount) + metadata.drop_all(engine_testaccount) @pytest.mark.skip(