Alpha-SQL icon indicating copy to clipboard operation
Alpha-SQL copied to clipboard

NameError: max_example_length is not defined in load_value_examples

Open j0ker70 opened this issue 6 months ago • 1 comments

Bug

Running bash script/preprocess.sh on a clean install crashes with:

File "alphasql/database/utils.py", line 160, in load_value_examples
    examples = execute_sql_without_timeout(db_path, f"SELECT DISTINCT `{column_name}` FROM `{table_name}` WHERE `{column_name}` IS NOT NULL AND
`{column_name}` != '' AND length(cast(`{column_name}` as text)) <= {max_example_length} LIMIT {max_num_examples};").result
NameError: name 'max_example_length' is not defined

Root cause

Commit c821bfd ("fix long context issue") added an AND length(cast(... as text)) <= {max_example_length} clause to the SQL f-string in load_value_examples, but max_example_length was never defined as a parameter, local variable, or module-level constant.

The current function signature is:

def load_value_examples(db_id: str, database_root_dir: str, table_name: str, column_name: str, max_num_examples: int = 3) -> List[str]:

— no max_example_length.

j0ker70 avatar May 25 '26 10:05 j0ker70

Fixed in 3d2fc69.

Summary:

  • Added max_example_length=100 to load_value_examples, so the length filter no longer references an undefined name and existing calls remain compatible.
  • Added regression tests for default and custom value-example length filtering.
  • Added the missing prettytable dependency required by alphasql.database.sql_execution.

Verified with:

  • .venv/bin/python -m unittest discover -s tests -p test_*.py
  • .venv/bin/python -m compileall alphasql tests

BugMaker-Boyan avatar May 26 '26 10:05 BugMaker-Boyan