File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -2571,6 +2571,8 @@ def insert_all(
2571
2571
all_columns = []
2572
2572
first = True
2573
2573
num_records_processed = 0
2574
+ # Fix up any records with square braces in the column names
2575
+ records = fix_square_braces (records )
2574
2576
# We can only handle a max of 999 variables in a SQL insert, so
2575
2577
# we need to adjust the batch_size down if we have too many cols
2576
2578
records = iter (records )
@@ -2618,7 +2620,6 @@ def insert_all(
2618
2620
column for column in record if column not in all_columns
2619
2621
]
2620
2622
2621
- validate_column_names (all_columns )
2622
2623
first = False
2623
2624
2624
2625
self .insert_chunk (
@@ -2986,3 +2987,14 @@ def validate_column_names(columns):
2986
2987
assert (
2987
2988
"[" not in column and "]" not in column
2988
2989
), "'[' and ']' cannot be used in column names"
2990
+
2991
+
2992
+ def fix_square_braces (records : Iterable [Dict [str , Any ]]):
2993
+ for record in records :
2994
+ if any ("[" in key or "]" in key for key in record .keys ()):
2995
+ yield {
2996
+ key .replace ("[" , "_" ).replace ("]" , "_" ): value
2997
+ for key , value in record .items ()
2998
+ }
2999
+ else :
3000
+ yield record
Original file line number Diff line number Diff line change @@ -144,6 +144,7 @@ def test_create_table_with_not_null(fresh_db):
144
144
[{"name" : "memoryview" , "type" : "BLOB" }],
145
145
),
146
146
({"uuid" : uuid .uuid4 ()}, [{"name" : "uuid" , "type" : "TEXT" }]),
147
+ ({"foo[bar]" : 1 }, [{"name" : "foo_bar_" , "type" : "INTEGER" }]),
147
148
),
148
149
)
149
150
def test_create_table_from_example (fresh_db , example , expected_columns ):
@@ -525,13 +526,6 @@ def test_insert_row_alter_table(
525
526
]
526
527
527
528
528
- def test_insert_row_alter_table_invalid_column_characters (fresh_db ):
529
- table = fresh_db ["table" ]
530
- table .insert ({"foo" : "bar" }).last_pk
531
- with pytest .raises (AssertionError ):
532
- table .insert ({"foo" : "baz" , "new_col[abc]" : 1.2 }, alter = True )
533
-
534
-
535
529
def test_add_missing_columns_case_insensitive (fresh_db ):
536
530
table = fresh_db ["foo" ]
537
531
table .insert ({"id" : 1 , "name" : "Cleo" }, pk = "id" )
You can’t perform that action at this time.
0 commit comments