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

Generated Enum types are not valid as parameters #419

Closed
asfaltboy opened this issue Mar 5, 2023 · 0 comments · Fixed by #425
Closed

Generated Enum types are not valid as parameters #419

asfaltboy opened this issue Mar 5, 2023 · 0 comments · Fixed by #425

Comments

@asfaltboy
Copy link

asfaltboy commented Mar 5, 2023

Describe the bug

When my schema contains a reference to an Enum type, then the code generator creates an enum.Enum subclass. However, I can pass an instance of this Enum type into a parameter function, and mypy is happy. However, when executing the code, I see the error:

>   ???
E   TypeError: a str or edgedb.EnumValue(__tid__=59ec73b8-4261-11ed-a3eb-b1b44f04f696) is expected as a valid enum argument, got Color

edgedb/protocol/./codecs/./enum.pyx:27: TypeError

Changing the passed argument to the Enum value (e.g Color.RED.value) results in mypy complaining that str is not a valid type.

Full trace back - click to expand!
test.py:62: in insert_shirt
    return await executor.query_single(
../../Library/Caches/pypoetry/virtualenvs/test-edgedb-bug/lib/python3.10/site-packages/edgedb/abstract.py:238: in query_single
    return await self._query(QueryContext(
../../Library/Caches/pypoetry/virtualenvs/test-edgedb-bug/lib/python3.10/site-packages/edgedb/base_client.py:739: in _query
    return await con.raw_query(query_context)
../../Library/Caches/pypoetry/virtualenvs/test-edgedb-bug/lib/python3.10/site-packages/edgedb/base_client.py:239: in raw_query
    raise e
../../Library/Caches/pypoetry/virtualenvs/test-edgedb-bug/lib/python3.10/site-packages/edgedb/base_client.py:234: in raw_query
    return await self._protocol.query(**args)
edgedb/protocol/protocol.pyx:594: in query
    ???
edgedb/protocol/protocol.pyx:559: in execute
    ???
edgedb/protocol/protocol.pyx:379: in _execute
    ???
edgedb/protocol/protocol.pyx:1125: in edgedb.protocol.protocol.SansIOProtocol.encode_args
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   ???
E   edgedb.errors.InvalidArgumentError: invalid input for query argument $color: <Color.RED: 'Red'> (a str or edgedb.EnumValue(__tid__=59ec73b8-4261-11ed-a3eb-b1b44f04f696) is expected as a valid enum argument, got Color)

edgedb/protocol/./codecs/./object.pyx:114: InvalidArgumentError

Reproduction

Given the schema:

scalar type Color extending enum<Red, Green, Blue>;

type Shirt {
  property color -> Color;
}

When we have a query:

select (
    insert Shirt {
        color := <Color>$color
    }
) { id, color };

Run edgedb-py, and execute:

insert_shirt(color=Color.RED)

Expected behavior

I expect to be able to pass the Enum value directly as a parameter, as it's the type declared by the code generator.

Versions (please complete the following information):

  • OS: macOS Ventura 13.2.1 (22D68)
  • EdgeDB version: 2.12+a5dfd9f
  • EdgeDB CLI version: 2.3.1+5d93f42
  • edgedb-python version: 1.3.0
  • Python version: 3.10.6

Additional context

Note: I raised another issue/question in discord regarding optional parameters: https://discord.com/channels/841451783728529451/849374935209607199/1081881229676265592

fantix added a commit that referenced this issue Apr 21, 2023
User-defined enums can be used interchangably with edgedb.EnumValue,
like the `__eq__` (`==`) test, `__hash__` (as dict key) or comparing
will pass between user enum and edgedb.EnumValue, but the `is` check
won't pass.

This fixes a typing issue in the codegen. Fixes #419
fantix added a commit that referenced this issue Apr 21, 2023
User-defined enums can be used interchangably with edgedb.EnumValue,
like the `__eq__` (`==`) test, `__hash__` (as dict key) or comparing
will pass between user enum and edgedb.EnumValue, but the `is` check
won't pass.

This fixes a typing issue in the codegen. Fixes #419
@fantix fantix mentioned this issue Apr 21, 2023
fantix added a commit that referenced this issue Apr 21, 2023
User-defined enums can be used interchangably with edgedb.EnumValue,
like the `__eq__` (`==`) test, `__hash__` (as dict key) or comparing
will pass between user enum and edgedb.EnumValue, but the `is` check
won't pass.

This fixes a typing issue in the codegen. Fixes #419
fantix added a commit that referenced this issue May 26, 2023
User-defined enums can be used interchangably with edgedb.EnumValue,
like the `__eq__` (`==`) test, `__hash__` (as dict key) or comparing
will pass between user enum and edgedb.EnumValue, but the `is` check
won't pass.

This fixes a typing issue in the codegen. Fixes #419
fantix added a commit that referenced this issue Jun 19, 2024
New Features
============

* Support EdgeDB 5.0 "branch" connection option
  (by @vpetrovykh in #484 #485 #487)

* Support EdgeDB 5.0 AI extension
  (by @fantix in #489 #490)

Breaking Changes
================

* Enum values can now compare to user-defined enums successfully (#425)
  (by @fantix in bb7522c for #419)

* Add optional default to codegen params (#426)
  (by @fantix in 21b024a for #422)

Changes
=======

* blocking client: fix connect and timeout, support IPv6 (#499)
  (by @fantix @zachary822 in 28a83fd for #486)

Fixes
=====

* Add test to check setting a computed global using with_globals. (#494)
  (by @dnwpark in 636bc0e for #494)

* Fix test and add Python 3.12 in CI
  (by @fantix in #498 #503)

* Use result of pydantic_dataclass, will silence linters (#501)
  (by @AdrienPensart in d88187a)

* Extract ExecuteContext as in/out argument (#500)
  (by @fantix in 2fb7965 for #493)
fantix added a commit that referenced this issue Jun 19, 2024
New Features
============

* Support EdgeDB 5.0 "branch" connection option
  (by @vpetrovykh in #484 #485 #487)

* Support EdgeDB 5.0 AI extension
  (by @fantix in #489 #490)

Breaking Changes
================

* Enum values can now compare to user-defined enums successfully (#425)
  (by @fantix in bb7522c for #419)

* Add optional default to codegen params (#426)
  (by @fantix in 21b024a for #422)

Changes
=======

* blocking client: fix connect and timeout, support IPv6 (#499)
  (by @fantix @zachary822 in 28a83fd for #486)

Fixes
=====

* Add test to check setting a computed global using with_globals. (#494)
  (by @dnwpark in 636bc0e for #494)

* Fix test and add Python 3.12 in CI
  (by @fantix in #498 #503)

* Use result of pydantic_dataclass, will silence linters (#501)
  (by @AdrienPensart in d88187a)

* Extract ExecuteContext as in/out argument (#500)
  (by @fantix in 2fb7965 for #493)
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

Successfully merging a pull request may close this issue.

1 participant