bulkcopy() fails with SQL error 7339 for UTF-8 multibyte characters against Fabric Warehouse
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 22/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Domínio
- databases, internationalization
Direção de pesquisa
The failing call is cursor.bulkcopy() with a non-ASCII value bound to a VARCHAR(100) column in a Latin1_General_100_BIN2_UTF8 Fabric Warehouse; the parameterized INSERT with the same string succeeds, so compare the two encoding paths. The payload names the mssql-python 1.16.0 package and the mssql-python-rs runtime, so start there to see how bulk data is encoded for varchar. Done means the reproduction inserts 'sofá' through bulkcopy and reads back the same value, and the ASCII control still passes.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Environment
mssql-python: 1.16.0
Python: 3.13.16
Target: Microsoft Fabric Warehouse
Authentication: ActiveDirectoryServicePrincipal
Microsoft ODBC Driver installed: 18.6.1.1
Target database collation: Latin1_General_100_BIN2_UTF8
Target column: VARCHAR(100)
Parameterized INSERT:
"/search/Individual sofá" succeeds
cursor.bulkcopy():
The same hardcoded Python string fails with SQL error 7339.
"Sql Error: 7339: Class 16: State 1: OLE DB provider 'STREAM' for linked server '(null)' returned invalid data for column"
ASCII control:
"/search/Individual sofa" succeeds.
Failing character:
á
Python UTF-8:
Characters = 23
Bytes = 24
Hex for ó = c3 b3
Target table:
DROP TABLE IF EXISTS [dbo].[BulkCopyUnicodeTest];
CREATE TABLE [dbo].[BulkCopyUnicodeTest]
(
[Field1] VARCHAR(100) NULL
);
Successful parameterized INSERT
unicode_value = "/search/Individual sofá"
fabric_cursor.execute(
"""
INSERT INTO [dbo].[BulkCopyUnicodeTest] ([Field1])
VALUES (?);
""",
(unicode_value,),
)
fabric_connection.commit()
The stored result: /search/Individual sofá
The following code fails with SQL error 7339:
unicode_value = "/search/Individual sofá"
result = fabric_cursor.bulkcopy(
table_name="[dbo].[BulkCopyUnicodeTest]",
data=[(unicode_value,)],
column_mappings=[(0, "Field1")],
batch_size=0,
timeout=300,
keep_nulls=True,
)
fabric_connection.commit()
Error:
RuntimeError: Sql Error: 7339: Class 16: State 1:
OLE DB provider 'STREAM' for linked server '(null)'
returned invalid data for column '[!BulkInsert].Field1'.
The following code succeed
#Replacing á with ASCII o allows the bulk copy to succeed:
ascii_value = "/search/Individual sofa"
fabric_cursor.execute("TRUNCATE TABLE [dbo].[BulkCopyUnicodeTest];")
fabric_connection.commit()
result = fabric_cursor.bulkcopy(
table_name="[dbo].[BulkCopyUnicodeTest]",
data=[(ascii_value,)],
column_mappings=[(0, "Field1")],
batch_size=0,
timeout=300,
keep_nulls=True,
)
fabric_connection.commit()
print(result)
Encoding details
unicode_value = "/search/Individual sofá"
print(len(unicode_value))
print(len(unicode_value.encode("utf-8")))
print(unicode_value.encode("utf-8").hex(" "))
Output
23
24
2f 73 65 61 72 63 68 2f 49 6e 64 69 76 69 64 75 61 6c 20 73 6f 66 c3 b3
python -m pip show mssql-python mssql-python-rs mssql-python-odbc
Name: mssql-python
Version: 1.16.0
Summary: A Python library for interacting with Microsoft SQL Server
Home-page: https://github.com/microsoft/mssql-python
Author: Microsoft Corporation
Author-email: [email protected]
License:
Requires: azure-identity, mssql-python-odbc, mssql-python-rs
Required-by:Name: mssql-python-rs
Version: 0.3.0
Summary: Rust-based native runtime (TDS core and ODBC driver) consumed by the mssql-python driver.
Home-page: https://github.com/microsoft/mssql-python
Author: Microsoft Corporation
Author-email:
License: MIT
Requires:
Required-by: mssql-pythonName: mssql-python-odbc
Version: 18.6.2.2
Summary: Internal implementation package for mssql-python: Microsoft ODBC Driver 18 for SQL Server binaries. Not intended for direct use.
Home-page: https://github.com/microsoft/mssql-python
Author: Microsoft Corporation
Author-email: [email protected]
License: Other/Proprietary License
Requires:
Required-by: mssql-python
Complete snippet
from contextlib import closing
import mssql_python
CLIENT_ID = ""
CLIENT_SECRET = ""
WAREHOUSE_SERVER = ""
WAREHOUSE_NAME = ""
FABRIC_CONNECTION_STRING = (
f"Server={WAREHOUSE_SERVER};"
f"Database={WAREHOUSE_NAME};"
"Authentication=ActiveDirectoryServicePrincipal;"
f"UID={CLIENT_ID};"
f"PWD={CLIENT_SECRET};"
"Encrypt=yes;"
"TrustServerCertificate=no;"
)
TABLE_NAME = "[dbo].[BulkCopyUnicodeTest]"
UNICODE_VALUE = "/search/Individual sofá"
ASCII_VALUE = "/search/Individual sofa"
with closing(mssql_python.connect(FABRIC_CONNECTION_STRING)) as fabric_connection:
with closing(fabric_connection.cursor()) as fabric_cursor:
fabric_cursor.execute(f"DROP TABLE IF EXISTS {TABLE_NAME};")
fabric_cursor.execute(f"""
CREATE TABLE {TABLE_NAME}
(
[Field1] VARCHAR(100) NULL
);
""")
fabric_connection.commit()
# Parameterized INSERT succeeds.
fabric_cursor.execute(
f"""
INSERT INTO {TABLE_NAME} ([Field1])
VALUES (?);
""",
(UNICODE_VALUE,),
)
fabric_connection.commit()
fabric_cursor.execute(f"SELECT [Field1] FROM {TABLE_NAME};")
print(f"Parameterized INSERT stored: {fabric_cursor.fetchone()[0]}")
# Clear the table before testing bulkcopy.
fabric_cursor.execute(f"TRUNCATE TABLE {TABLE_NAME};")
fabric_connection.commit()
# ASCII bulkcopy control succeeds.
ascii_result = fabric_cursor.bulkcopy(
table_name=TABLE_NAME,
data=[(ASCII_VALUE,)],
column_mappings=[(0, "Field1")],
batch_size=0,
timeout=300,
keep_nulls=True,
)
fabric_connection.commit()
print(f"ASCII bulkcopy succeeded: {ascii_result}")
# Clear the table before testing the Unicode value.
fabric_cursor.execute(f"TRUNCATE TABLE {TABLE_NAME};")
fabric_connection.commit()
print(f"Unicode characters: {len(UNICODE_VALUE)}")
print(f"Unicode UTF-8 bytes: {len(UNICODE_VALUE.encode('utf-8'))}")
print(f"Unicode UTF-8 hex: {UNICODE_VALUE.encode('utf-8').hex(' ')}")
# Unicode bulkcopy fails with SQL error 7339.
unicode_result = fabric_cursor.bulkcopy(
table_name=TABLE_NAME,
data=[(UNICODE_VALUE,)],
column_mappings=[(0, "Field1")],
batch_size=0,
timeout=300,
keep_nulls=True,
)
fabric_connection.commit()
print(f"Unicode bulkcopy succeeded unexpectedly: {unicode_result}")
- Linguagem predominante
- Python
- Estrelas
- 479
- Forks
- 62
- Merge médio
- 2d 23h
- PRs com merge (30d)
- 18
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de microsoft/mssql-python
-
bulkcopy accepts four-part table names that SQL Server always rejectsTalvez já em andamento @jahnvi480 assumiu há 1 dia. Abertaarea: bulk-copy bug inADO triage done under development
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
microsoft/mssql-python#843 · 1 comentário · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
triage needed
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
microsoft/mssql-python#854 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
triage needed
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 38/100
microsoft/mssql-python#850 · 1 comentário · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
bulkcopy() & bulkcopy_arrow() fail with Schannel AcquireCredentialsHandleW error 0x8009030D (SEC_E_UNKNOWN_CREDENTIALS)Talvez já em andamento @jahnvi480 assumiu há 1 dia. Abertaarea: bulk-copy bug inADO triage done
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 20/100
microsoft/mssql-python#848 · 5 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
macOS: encrypted connections fail after Homebrew moved the `openssl` alias to `openssl@4`Talvez já em andamento @bewithgaurav assumiu há 21 dias. Abertaarea: packaging-platform bug triage needed
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
microsoft/mssql-python#826 · 2 comentários · 2 reações · 1 responsável ·
Mantenedores costumam responder em até 1 dia
Todas as issues de microsoft/mssql-python
Issues semelhantes
-
[Bug] Unit tests reach real Bedrock call paths without patching the modelTalvez já em andamento @proton0210 assumiu hoje. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
aws-samples/sample-aws-genai-db-modernizer#1318 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
pyarrow-25.0.1-cp310-cp310-manylinux_2_28_x86_64.whl: 1 vulnerabilities (highest severity is: 5.3)AbertaMend: dependency security vulnerability
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
capitalone/locopy#394 ·
-
[Bug] Unhandled ValueError terminates watchdog thread when GISRC value contains multiple colonsAbertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia
-
sdk-typescript: unquoted COPY globs in shell form are silently dropped from the image build contextAbertabug javascript
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
ietf-tools/datatracker#11922 · 1 comentário ·
Mantenedores costumam responder em até 1 dia