Skip to content

SNOW-2090775: converter doesn't properly convert lists of bytes #2311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jeffsawatzky opened this issue May 6, 2025 · 2 comments · May be fixed by #2312
Closed

SNOW-2090775: converter doesn't properly convert lists of bytes #2311

jeffsawatzky opened this issue May 6, 2025 · 2 comments · May be fixed by #2312
Assignees
Labels
bug status-triage_done Initial triage done, will be further handled by the driver team

Comments

@jeffsawatzky
Copy link

jeffsawatzky commented May 6, 2025

Python version

3.12.10

Operating system and processor architecture

macOS-15.4.1-x86_64-i386-64bit

Installed packages

snowflake-connector-python 3.15.0
snowflake-sqlalchemy       1.7.3
SQLAlchemy                 1.4.54

What did you do?

I am trying to run a query like this:

business_uuid = UUID("4363f57d-c9ca-4e63-92c7-3e67786c8a30")
user_uuid = UUID("4363f57d-c9ca-4e63-92c7-3e67786c8a30")
stmt = text(
   "SELECT * FROM users WHERE business_uuid = :business_uuid AND user_uuid IN [:user_uuids]"
)
conn.cursor().execute(
   stmt,
   params={"business_uuid": business_uuid.bytes, "user_uuids": [user_uuid.bytes]},
)

But it is throwing the following error:

.venv/lib/python3.12/site-packages/snowflake/connector/connection.py:1867: in _process_single_param
    return _quote(escape(to_snowflake(param)))
.venv/lib/python3.12/site-packages/snowflake/connector/converter.py:483: in to_snowflake
    return getattr(self, f"_{type_name}_to_snowflake")(value)
.venv/lib/python3.12/site-packages/snowflake/connector/converter.py:626: in _list_to_snowflake
    SnowflakeConverter.quote(v0)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

value = b';\xe7\x0czb\xa8Kd\xad\x87|G\xae\x8b\xfcM'

    @staticmethod
    def quote(value) -> str:
        if isinstance(value, list):
            return ",".join(value)
        if value is None:
            return "NULL"
        elif isinstance(value, bool):
            return "TRUE" if value else "FALSE"
        elif IS_NUMERIC(value):
            return str(repr(value))
        elif IS_BINARY(value):
            # Binary literal syntax
>           return "X'{}'".format(value.decode("ascii"))
E           UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 1: ordinal not in range(128)

.venv/lib/python3.12/site-packages/snowflake/connector/converter.py:722: UnicodeDecodeError

For the single business param, to_snowflake is called on the value which results in _bytes_to_snowflake and therefore binary_to_snowflake being called on the value.

For in the case of the list, the to_snowflake call isn't called per each list item, and therefore to_snowflake isn't called.

What did you expect to see?

I expect the list of uuid bytes to be converted properly without error.

Can you set logging to DEBUG and collect the logs?

@github-actions github-actions bot changed the title converter doesn't properly convert lists of bytes SNOW-2090775: converter doesn't properly convert lists of bytes May 6, 2025
jeffsawatzky added a commit to jeffsawatzky/snowflake-connector-python that referenced this issue May 6, 2025
@jeffsawatzky
Copy link
Author

#2312 is a PR to address this issue

@sfc-gh-dszmolka sfc-gh-dszmolka self-assigned this May 6, 2025
@sfc-gh-dszmolka sfc-gh-dszmolka added status-triage_done Initial triage done, will be further handled by the driver team and removed needs triage labels May 6, 2025
@sfc-gh-dszmolka
Copy link
Contributor

hi - thanks for reporting this issue and especially for submitting a possible fix with the PR , too !
I see a support case (01019378) was also raised for the same issue, so I'm now closing this GH issue as a duplicate to allow focus the efforts on one ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants