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

Fix encoder if a class is passed #247

Merged
merged 2 commits into from May 31, 2023
Merged

Fix encoder if a class is passed #247

merged 2 commits into from May 31, 2023

Conversation

Psykopear
Copy link
Contributor

Our encoder fails if a class is passed as an argument to one of the operators, because we try to call obj.__getstate__(), and the class doesn't pass the self parameter in this case.

That can happen if we want to use a class __init__ method in an operator:

class Device:
    def __init__(self):
        ...
    def update_avg(self, data):
        ...

flow.stateful_map("average", Device, Device.update_avg)

Here we implicitely want to use Device.__init__, but we are passing the class Device itself to the operator. When we try to encode it, we try to call obj.__getstate__(), but that fails since we are not passing an instance.

This fix prevents that by returning the name of the class if the passed object is, in fact, a class

@Psykopear Psykopear merged commit 278348e into main May 31, 2023
21 checks passed
@Psykopear Psykopear deleted the fix-encoder branch May 31, 2023 09:37
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 this pull request may close these issues.

None yet

3 participants