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

Codegen should raise an error if a variable/argument is named query #497

Open
jimkring opened this issue May 26, 2024 · 0 comments
Open

Comments

@jimkring
Copy link

Describe the bug

If an .edgeql contains a variable named $query codegen should raise an error or otherwise avoid the collision with the existing query argument of the edgedb.AsyncIOExecutor.query() method (whose signature looks like this: async def query(self, query: str, *args, **kwargs) -> list:)

More Details*

See Issue #496.

I have an .edgeql that looks like this: select ext::ai::search(MyModel, <array<float32>>$query)

edgeql-py generates python code that looks like this:

async def ai_search(
    executor: edgedb.AsyncIOExecutor,
    *,
    query: list[float],
) -> list[AiSearchResult]:
    return await executor.query(
        """\
        select ext::ai::search(MyModel, <array<float32>>$query)\
        """,
        query=query,
    )

The problem is that the first argument of edgedb.AsyncIOExecutor.query() is named query, which means that the use of the named argument actually overwrites the first. For example, what is really going on is this (note that query is being passed twice).

async def ai_search(
    executor: edgedb.AsyncIOExecutor,
    *,
    query: list[float],
) -> list[AiSearchResult]:
    return await executor.query(
        query="""\
        select ext::ai::search(MyModel, <array<float32>>$query)\
        """,
        query=query,
    )

Then, I get a runtime error stating: TypeError: AsyncIOReadOnlyExecutor.query() got multiple values for argument 'query' -- it wasn't obvious to me what was going on, since my query argument was a list[float] and I thought it was a problem with it being a list. I didn't realize the root of the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant