geldata / geldata/gel-python

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

Open
#497 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
415
Forks
50
PR merge metrics
No merged PRs in 30d

Description

**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, >$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, >$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, >$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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.