Skip to content

SNOW-522645: Passing session_parameters in a url cause an internal error inside the Snowflake connector #266

@njriasan

Description

@njriasan

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using (python --version)?

3.8.11

  1. What operating system and processor architecture are you using (python -c 'import platform; print(platform.platform())')?

macOS-10.16-x86_64-i386-64bit

  1. What are the component versions in the environment (pip list)?

I'm using an anaconda environment.

snowflake-connector-python 2.7.2 py38h27c1234_0 conda-forge
snowflake-sqlalchemy 1.3.3 pyhd8ed1ab_0 conda-forge
sqlalchemy 1.4.23 pypi_0 pypi

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.

I tried to run a simple read_query using a Pandas query with session parameters included. The error is simply a parsing error so I have filled the session parameter with a dummy value.

import os

username = os.environ["SF_USER"]
password = os.environ["SF_PASSWORD"]
account = "my_snowflake_account"
db = "SNOWFLAKE_SAMPLE_DATA"
schema = "TPCH_SF1"
connection_params = {
        "warehouse": "DEMO_WH",
        # Here is the issue 
        "session_parameters": json.dumps({"DUMMY": 0}),
        "paramstyle": "pyformat",
        "insecure_mode": True,
}
conn = f"snowflake://{username}:{password}@{account}/{db}/{schema}?{urllib.parse.urlencode(connection_params)}"

query = "SELECT * FROM LINEITEM ORDER BY L_ORDERKEY, L_PARTKEY, L_SUPPKEY LIMIT 70"

df = pd.read_sql(query, conn)
print(df)
  1. What did you expect to see?

The table should be successfully loaded without any issues.

  1. What did you see instead?

An internal error inside the snowflake connector.

        if self._autocommit is not None:
>           self._session_parameters[PARAMETER_AUTOCOMMIT] = self._autocommit
E           TypeError: 'str' object does not support item assignment

Earlier in this file the snowflake connector states that this parameter should either be a dictionary or None. I believe this parameter needs to be converted from a json string back to a dictionary before the Snowflake connection is created.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions