VARBYTE is decoded into utf-8

Open
#261 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
database

Research direction

Run the supplied Python reproduction against Redshift and inspect the connector's VARBYTE result-decoding path when the final query executes. Confirm that VARBYTE values are returned as Python bytes without a UnicodeDecodeError, then add or update coverage for the demonstrated query behavior.

Written by the indexing model from the issue text.

Description

In readme VARBYTE is stated as supported as Python's bytes type. When trying to query data VARBYTE data from Redshift, 'utf-8' decoding error is thrown.

Reproduction
import redshift_connector


DROP_DDL = "drop table if exists varbyte_repro"
CREATE_DDL = """create table varbyte_repro(
    my_var varbyte
);
"""
INSERT_DML = "insert into varbyte_repro(my_var) values (from_hex(SHA1('hello')))"
QUERY = "select * from varbyte_repro"

with redshift_connector.connect(
    host="replaced",
    database="replaced",
    user="replaced",
    password="replaced",
) as conn, conn.cursor() as cursor:
    conn.autocommit = True
    cursor.execute(DROP_DDL)
    cursor.execute(CREATE_DDL)
    cursor.execute(INSERT_DML)
    cursor.execute(QUERY)
Expected

Last cursor.execute runs without issue (so that later something like cursor.fetchall could be used)

Actual

Error thrown:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaa in position 0: invalid start byte
Dominant language
Python
Stars
220
Forks
86
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aws/amazon-redshift-python-driver

All issues in aws/amazon-redshift-python-driver

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.