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

Use enum (or any type) as argumenets #30

Closed
trim21 opened this issue Dec 26, 2021 · 8 comments
Closed

Use enum (or any type) as argumenets #30

trim21 opened this issue Dec 26, 2021 · 8 comments

Comments

@trim21
Copy link

trim21 commented Dec 26, 2021

I'm trying to build a query like this Table.column == TopicState.TOPIC_STATE_NONE, but I got a ValueError

TypeError: Argument 'value' has incorrect type (expected str, got TopicState)

  File "asyncmy\connection.pyx", line 426, in asyncmy.connection.Connection.literal
  File "asyncmy\connection.pyx", line 419, in asyncmy.connection.Connection.escape
  File "asyncmy\converters.pyx", line 10, in asyncmy.converters.escape_item
  File "asyncmy\converters.pyx", line 25, in asyncmy.converters.escape_item
TypeError: Argument 'value' has incorrect type (expected str, got TopicState)

To avoid this, I need to Table.column == TopicState.TOPIC_STATE_NONE.value to get enum's underlying value.

In aiomysql, I can add a method translate(self, _escape_table) to support any type, is there any way in asyncmy we can do this?

@long2ice
Copy link
Owner

Could you give link for that?

@trim21
Copy link
Author

trim21 commented Dec 27, 2021

do you mean translate?

@long2ice
Copy link
Owner

Yes

@trim21
Copy link
Author

trim21 commented Dec 27, 2021

didn't find doc about this, but it's raised in the exception message

@long2ice
Copy link
Owner

OK

@trim21
Copy link
Author

trim21 commented Dec 27, 2021

Maybe it's a undefined behavior? What ever, it would be better if we can use enum value directly.

long2ice added a commit that referenced this issue Dec 27, 2021
@long2ice
Copy link
Owner

Fixed

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

2 participants