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

Fix problem with sql_chain and quotation marks: normalize_sql_cmd #3385

Closed
wants to merge 10 commits into from
Closed
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
PhilipMay committed May 4, 2023
commit e4783d2c770d2f50de84d59bdcf7a54154bb5efe
29 changes: 29 additions & 0 deletions tests/unit_tests/chains/test_sql_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Test chain for interacting with SQL Database."""

import pytest

from langchain.chains.sql_database.base import SQLDatabaseChain


def test_normalize_sql_cmd_double_quotation_marks():
sql_cmd = ' "SELECT * from fake "'
result = SQLDatabaseChain.normalize_sql_cmd(sql_cmd)
assert result == "SELECT * from fake"


def test_normalize_sql_cmd_single_quotation_marks():
sql_cmd = " 'SELECT * from fake '"
result = SQLDatabaseChain.normalize_sql_cmd(sql_cmd)
assert result == "SELECT * from fake"


@pytest.mark.parametrize("sql_cmd", ["", '"', "'", "x", None])
def test_normalize_sql_cmd_no_change(sql_cmd):
result = SQLDatabaseChain.normalize_sql_cmd(sql_cmd)
assert result == sql_cmd # no change


def test_normalize_sql_cmd_two_double_quotation_marks():
sql_cmd = '""'
result = SQLDatabaseChain.normalize_sql_cmd(sql_cmd)
assert result == "" # empty string