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

InOutFlow broken with python >=3.11 #6787

Closed
jc-harrison opened this issue Sep 6, 2024 · 2 comments · Fixed by #6789
Closed

InOutFlow broken with python >=3.11 #6787

jc-harrison opened this issue Sep 6, 2024 · 2 comments · Fixed by #6789
Labels
bug Something isn't working FlowMachine Issues related to FlowMachine

Comments

@jc-harrison
Copy link
Member

Describe the bug
flowmachine.features.location.flows.InOutFlow has a direction parameter to specify whether the query is an inflow or an outflow. We use the following enum to ensure the direction is either "to" or "from":

class Direction(str, Enum):
    OUTFLOW = "from"
    INFLOW = "to"

The str mixin ensured that Direction objects could be used as strings, e.g. f"pcod_{self.direction}" formats to either "pcod_from" or "pcod_to".

But python 3.11 changes this behaviour (see https://blog.pecar.me/python-enum for a description of the change), so that f"pcod_{self.direction}" formats to "pcod_Direction.INFLOW" or "pcod_Direction.OUTFLOW", which breaks the in/outflow SQL query.

Python 3.11 introduces a StrEnum class that can be used instead. So either we can make the definition of Direction conditional on the python version, or we can explicitly use direction.value instead of direction for string formatting.

I suspect there are other places we use the class MyEnum(str, Enum) hack, which may also be broken.

@jc-harrison jc-harrison added bug Something isn't working FlowMachine Issues related to FlowMachine labels Sep 6, 2024
@greenape
Copy link
Member

greenape commented Sep 9, 2024

Ouch, there are a bunch. Could replace with strenum and make 3.11 the min version?

@jc-harrison
Copy link
Member Author

Ouch, there are a bunch. Could replace with strenum and make 3.11 the min version?

Probably sensible. It's about time we bump the python version in the docker image anyway.

@greenape greenape mentioned this issue Sep 9, 2024
8 tasks
@mergify mergify bot closed this as completed in #6789 Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working FlowMachine Issues related to FlowMachine
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants