-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-118945: Fix ArgumentError where insert with autoincrement failed…
… due to incompatible column type affinity (#297) * bug fix * fix old test * add autoincrement test * fix tests * review feedbacks * consistent naming
- Loading branch information
1 parent
e2cb627
commit 3f7ed9e
Showing
6 changed files
with
104 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2012-2019 Snowflake Computing Inc. All right reserved. | ||
# | ||
|
||
from sqlalchemy import Column, Integer, MetaData, Sequence, String, Table, select | ||
|
||
|
||
def test_table_with_sequence(engine_testaccount, db_parameters): | ||
# https://github.com/snowflakedb/snowflake-sqlalchemy/issues/124 | ||
test_table_name = 'sequence' | ||
test_sequence_name = f'{test_table_name}_id_seq' | ||
sequence_table = Table(test_table_name, MetaData(), | ||
Column('id', Integer, Sequence(test_sequence_name), primary_key=True), | ||
Column('data', String(39)) | ||
) | ||
sequence_table.create(engine_testaccount) | ||
seq = Sequence(test_sequence_name) | ||
try: | ||
engine_testaccount.execute(sequence_table.insert(), [{'data': 'test_insert_1'}]) | ||
|
||
select_stmt = select([sequence_table]).order_by('id') | ||
result = engine_testaccount.execute(select_stmt).fetchall() | ||
assert result == [(1, 'test_insert_1')] | ||
|
||
autoload_sequence_table = Table(test_table_name, MetaData(), autoload=True, autoload_with=engine_testaccount) | ||
|
||
engine_testaccount.execute(autoload_sequence_table.insert(), | ||
[{'data': 'multi_insert_1'}, {'data': 'multi_insert_2'}]) | ||
|
||
engine_testaccount.execute(autoload_sequence_table.insert(), [{'data': 'test_insert_2'}]) | ||
|
||
nextid = engine_testaccount.execute(seq) | ||
engine_testaccount.execute(autoload_sequence_table.insert(), [{'id': nextid, 'data': 'test_insert_seq'}]) | ||
result = engine_testaccount.execute(select_stmt).fetchall() | ||
assert result == [ | ||
(1, 'test_insert_1'), | ||
(2, 'multi_insert_1'), | ||
(3, 'multi_insert_2'), | ||
(4, 'test_insert_2'), | ||
(5, 'test_insert_seq') | ||
] | ||
finally: | ||
sequence_table.drop(engine_testaccount) | ||
seq.drop(engine_testaccount) | ||
|
||
|
||
def test_table_with_autoincrement(engine_testaccount, db_parameters): | ||
# https://github.com/snowflakedb/snowflake-sqlalchemy/issues/124 | ||
test_table_name = 'sequence' | ||
autoincrement_table = Table(test_table_name, MetaData(), | ||
Column('id', Integer, autoincrement=True, primary_key=True), | ||
Column('data', String(39)) | ||
) | ||
autoincrement_table.create(engine_testaccount) | ||
try: | ||
engine_testaccount.execute(autoincrement_table.insert(), [{'data': 'test_insert_1'}]) | ||
|
||
select_stmt = select([autoincrement_table]).order_by('id') | ||
result = engine_testaccount.execute(select_stmt).fetchall() | ||
assert result == [(1, 'test_insert_1')] | ||
|
||
autoload_sequence_table = Table(test_table_name, MetaData(), autoload=True, autoload_with=engine_testaccount) | ||
|
||
engine_testaccount.execute(autoload_sequence_table.insert(), | ||
[{'data': 'multi_insert_1'}, {'data': 'multi_insert_2'}]) | ||
|
||
engine_testaccount.execute(autoload_sequence_table.insert(), [{'data': 'test_insert_2'}]) | ||
|
||
result = engine_testaccount.execute(select_stmt).fetchall() | ||
assert result == [ | ||
(1, 'test_insert_1'), | ||
(2, 'multi_insert_1'), | ||
(3, 'multi_insert_2'), | ||
(4, 'test_insert_2'), | ||
] | ||
finally: | ||
autoincrement_table.drop(engine_testaccount) |