Skip to content

Bug: load_sql_files() fails for single file paths — NotADirectoryError / SQLFileNotFoundError #374

@tjpalanca

Description

@tjpalanca

Description

Calling SQLSpec.load_sql_files() with a path to a single .sql file raises SQLFileNotFoundError. The underlying error is NotADirectoryError: [Errno 20] Not a directory: '/path/to/hello.sql/.'.

URL to code causing the issue

No response

MCVE

import tempfile
from pathlib import Path

from sqlspec import SQLSpec

# Write a sample SQL file into a temp directory
with tempfile.TemporaryDirectory() as tmpdir:
    sql_file = Path(tmpdir) / "hello.sql"
    sql_file.write_text("-- name: hello_world\nselect 'Hello, World!' as greeting;\n")

    sqlspec = SQLSpec()

    # Both of these fail:
    # Option 1: load a single file
    sqlspec.load_sql_files(str(sql_file))

    # Option 2: load from the directory
    # sqlspec.load_sql_files(tmpdir)

    print(sqlspec.get_sql("hello_world"))

Steps to reproduce

See reproduction above.

Screenshots

N/A

Logs

Package Version

0.40.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions