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

feat: implement magic methods #633

Merged
merged 8 commits into from Mar 18, 2022
Merged

feat: implement magic methods #633

merged 8 commits into from Mar 18, 2022

Conversation

EdVraz
Copy link
Contributor

@EdVraz EdVraz commented Mar 10, 2022

Implement magic methods to make usage of models easier for users

Checklist

@EdVraz EdVraz added the enhancement New feature or request label Mar 10, 2022
@EdVraz EdVraz requested review from FayeDel and i0bs March 10, 2022 18:09
@EdVraz EdVraz linked an issue Mar 10, 2022 that may be closed by this pull request
1 task
@EdVraz EdVraz enabled auto-merge (squash) March 10, 2022 18:12
@EdVraz
Copy link
Contributor Author

EdVraz commented Mar 11, 2022

oh i forgot embed

@EdVraz EdVraz disabled auto-merge March 11, 2022 15:48
Copy link
Contributor

@i0bs i0bs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried adding this __setattr__ magic style into the serializer itself? The issue boils down to trying to recursively remap the attributes we've added to our serialization subclass.

@EdVraz
Copy link
Contributor Author

EdVraz commented Mar 13, 2022

I don't quite understand how you mean that

@FayeDel
Copy link
Collaborator

FayeDel commented Mar 13, 2022

I believe they were asking if you've tried implementing this:

    def __setattr__(self, key, value) -> None:
        super().__setattr__(key, value)
        if key != "_json" and (key not in self._json or value != self._json.get(key)):
            if value is not None and value is not MISSING:
                self._json.update({key: value})

            elif value is None and key in self._json.keys():
                del self._json[key]

within the serialiser mixin itself and not just the objects in question

@EdVraz
Copy link
Contributor Author

EdVraz commented Mar 14, 2022

I didn't do that, I also don't see where it would be useful since it is only called once and the other __setattr__ methods are updating the json correctly, so how would it help having it in the mixin?

@EdVraz EdVraz enabled auto-merge (squash) March 18, 2022 15:03
@EdVraz EdVraz merged commit e456a9e into interactions-py:unstable Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

[REQUEST] automatically update _json in models to make user changes to them easier
3 participants