Skip to content
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

[BUG]SQL Execution Canceled During INSERT Operation in Snowflake #1716

Open
HannaHUp opened this issue Jan 9, 2025 · 13 comments
Open

[BUG]SQL Execution Canceled During INSERT Operation in Snowflake #1716

HannaHUp opened this issue Jan 9, 2025 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@HannaHUp
Copy link

HannaHUp commented Jan 9, 2025

Bug Description
What happened?
An unexpected error occurs while attempting to execute an INSERT operation in Snowflake using snowflake-connector. The transaction is canceled with a ProgrammingError, citing that the transaction is being committed, and SQL execution is canceled.

To Reproduce
Which steps should someone take to run into the same error? A small, reproducible code example is useful here.
Unfortunately, I cannot reliably reproduce the error myself as it happens intermittently. However, it occurs quite often during execution.

Expected behavior
A clear and concise description of what you expected to happen.
The data should be successfully saved into Snowflake without any errors.

Relevant Logs/Tracebacks
Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. If the issue is related to the TruLens dashboard, please also include a screenshot.

`un unexpected error occurred: (snowflake.connector.errors.ProgrammingError) 000614 (57014): 01b99a49-0512-a1e0-0074-820306b2185a: Transaction '5c518634-c4c0-471c-8d8a-bd20b4dd453e', id '1736452409002000000', was committed, SQL execution canceled.
[SQL: INSERT INTO trulens_records (record_id, app_id, input, output, record_json, tags, ts, cost_json, perf_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)]

(Background on this error at: https://sqlalche.me/e/20/f405)`

Environment:

  • OS: [e.g. MacOS, Windows]
  • Python Version
  • TruLens version
  • Versions of other relevant installed libraries

Additional context
Add any other context about the problem here.

`def initialize_sessions(sf_settings: dict, password: str) -> Tuple[Session, TruSession]:
"""
Initialize Snowpark session and TruLens session.
"""
sf_config = sf_settings.copy()
sf_config.update({
"connection_timeout": 300, # 5 minutes
"client_session_keep_alive": True,
"session_timeout": 600 # 10 minutes
})

# Create Snowpark session
snowpark_session = Session.builder.configs(sf_settings).create()
print("Snowpark session created successfully.")

# Initialize SnowflakeConnector for TruLens
conn = SnowflakeConnector(
    snowpark_session=snowpark_session,
    password=password,
    database_redact_keys=True
)

# Create TruSession
session = TruSession(connector=conn)
# session.reset_database()
print("TruSession initialized and database reset.")
return snowpark_session, session

with tru_app:
response = retrieval_app.ask_question(
query=qa.get("question"),
)
print(f"Response: {response}")
`

@HannaHUp HannaHUp added the bug Something isn't working label Jan 9, 2025
@sfc-gh-jreini
Copy link
Contributor

Hey @HannaHUp - are you using SQL to call Snowflake Cortex in your app? That may be the cause here. Can you change it to use the python API?

@HannaHUp
Copy link
Author

HannaHUp commented Jan 9, 2025

are you using SQL to call Snowflake Cortex in your app? That may be the cause here. Can you change it to use the python API?

Thank you for your response! I believe I am already using the Python API to interact with Snowflake. Specifically, I am using the SnowflakeConnector class from trulens.connectors.snowflake

`
snowpark_session = Session.builder.configs(sf_settings).create()
print("Snowpark session created successfully.")

conn = SnowflakeConnector(
    snowpark_session=snowpark_session,
    password=password,
    database_redact_keys=True
)

session = TruSession(connector=conn)
return snowpark_session, session

`

@sfc-gh-jreini
Copy link
Contributor

can you share your app code?

@HannaHUp
Copy link
Author

HannaHUp commented Jan 9, 2025

trulens_sf.zip
@sfc-gh-jreini
Here it is.
Thank you

@HannaHUp
Copy link
Author

HannaHUp commented Jan 9, 2025

#1717
I also have this NaN issue from the same code.

@sfc-gh-jreini
Copy link
Contributor

Looking at your code, feel like I'm missing where your app is actually defined. Is there additional code where you set up ConversationalRetrievalAgent? Or is that imported (like from langchain? the import for that isn't in the .py)

@HannaHUp
Copy link
Author

HannaHUp commented Jan 9, 2025

trulens_sf.zip
@sfc-gh-jreini
Sorry. Here is the additional code where I set up ConversationalRetrievalAgent.

@sfc-gh-jreini
Copy link
Contributor

One possible issue here is that the output of ask_question is returned in a different order depending on if expected_output is included as an arg.

This is because on_output() feedback selector is selecting the first output of your function. But in the cases where ask_question doesn't get an expected_output, the first output of the function is context_docs instead of generated_message.

I'd recommend switching the order of the method output so that generated_message is always the first value returned in the Tuple. So in L100, change return context_docs, generated_message to return generated_message, context_docs

@HannaHUp
Copy link
Author

HannaHUp commented Jan 9, 2025

Hi,
Thank you for the suggestion. We define a list of questions and answers in qa_list, so we always expect consistent output for this test case. However, we’ve observed inconsistent results—sometimes we get the expected result, and other times we don’t.

We’ll also modify the order of the method output.

@sfc-gh-jreini
Copy link
Contributor

Good to know. Let me know if changing the order of the method output helps or if you're still seeing issues - thanks!

@sfc-gh-jreini
Copy link
Contributor

Hey @HannaHUp - we discovered some incompatibility with snowflake-sqlalchemy v1.7.2 that may also be causing this issue. Can you test with snowflake-sqlalchemy==1.7.1 or earlier? Thanks!

@HannaHUp
Copy link
Author

HannaHUp commented Jan 10, 2025

@sfc-gh-jreini
The issue is fixed by downgrading snowflake-sqlalchemy to 1.7.1!

@sfc-gh-dhuang
Copy link
Contributor

@HannaHUp
we have a pending PR to resolve this incompatibility in the latest snowflake-sqlalchemy #1719

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants