-
Notifications
You must be signed in to change notification settings - Fork 3
Convert results from digitalocean objects to dicts and lists #3
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
Conversation
Before This FixAfter This Fix |
|
LGTM, But some test cases for function which converts those custom objects would be nice :) |
actions/lib/action.py
Outdated
| # The results received from the digitalocean module are | ||
| # custom python objects that StackStorm doesn't recognize. | ||
| # The following code converts them into dicts & lists | ||
| json_str = json.dumps(digitalocean_results, default=digitalocean_obj_to_dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would also throw if an object contains an attribute which is datetime class instance or instance of another class which is not JSON serializable, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct.
Any other thoughts or idiomatic ways of converting custom python objects into dicts/lists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing simple I can think of.
This should work for now, as long as the class doesn't contain attributes which are not JSON serializable.
Otherwise the best way would probably be to manually build up the dict and exclude those attributes (we already do this in some other places like aws pack, etc.).
|
@Kami I took some time and wrote unit tests for the functionality i added. When doing this i noticed there were no unit tests at all for this pack so i went ahead and did a first pass at some tests. Unfortunately i'm not too familiar with this pack or with Digital Ocean so any comments/suggestions are appreciated. |
|
Great, thanks for working on the tests - will have a look shortly :) |
| @@ -0,0 +1,3 @@ | |||
| ## Pack Contributors | |||
| * st2dev info@stackstorm.com | |||
| * Encore Technologies code@encore.tech | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also add this to contributors field (array) in pack.yaml :)
|
Merged - thanks. Will also add you as a contributor to this repo :) |
Fix for #2
This parses the custom digitalocean objects and converts them into dicts and lists so StackStorm can understand them.