-
Notifications
You must be signed in to change notification settings - Fork 421
feat(event_sources): Add __str__ to Data Classes base DictWrapper #2129
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(event_sources): Add __str__ to Data Classes base DictWrapper #2129
Conversation
One area where I need assistance is noting what properties throughout the Data Classes should be blacklisted. |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## develop #2129 +/- ##
===========================================
- Coverage 97.47% 97.46% -0.01%
===========================================
Files 147 147
Lines 6809 6872 +63
Branches 483 505 +22
===========================================
+ Hits 6637 6698 +61
- Misses 136 137 +1
- Partials 36 37 +1
... and 10 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
aws_lambda_powertools/utilities/data_classes/code_pipeline_job_event.py
Outdated
Show resolved
Hide resolved
0626b6a
to
89484f2
Compare
Moving back to draft.
This broke due to the wrong input data going to the wrong wrapper. |
d7c47cc
to
9a0acbe
Compare
Have updated to show
|
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.
Hi @neilramsay, thank you very much for sending this PR, it is very useful when debugging an event and having the values of all fields with just a print
. And protecting sensitive fields that shouldn't be saved in the log makes perfect sense, very useful indeed!
32c9001
to
5d003c7
Compare
aws_lambda_powertools/utilities/data_classes/code_pipeline_job_event.py
Outdated
Show resolved
Hide resolved
Add in a __str__ method to the base class used by all Data Classes. This provides a dictionary string primarily for debugging purposes. To construct the dictionary a helper method _str_helper recursively works through `properties` in each instance of a Data Class. Some Data Classes have sensitive properties, such as credentials, which can be excluded by setting the `_sensitive_properties` attribute (list of strings). These properties will have their value replaced with "[SENSITIVE]", which allows a developer to see a value arrived, but was hidden as it is sensitive.
Update Data Classes documentation to mention Data Classes can be inspected with str(), and include example.
5d003c7
to
0e724c8
Compare
Add tests for DictWrapper str() functionality, including Data Classes with: - no properties - single property - sensitive property - recursive properties (Data Classes inside Data Classes) - exceptions reading properties - exceptions when transforming a list with DictWrapper subclasses inside
Add _sensitive_properties for CodePipelineArtifactCredentials to prevent logging out the secret_access_key and session_token properties.
0e724c8
to
6362732
Compare
@leandrodamascena is this an area we need to discuss further, or is this something for separate PRs? |
I looked quickly through all the classes and didn't see any fields that demand be sensitive, like But yes, it makes a lot of sense for us to discuss this in other PRs as the need arises. |
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.
@neilramsay I don't see anything else we need to change and we're ready to merge this PR! If you have no other considerations, I'll merge this!
Thank you @leandrodamascena for your patience, and guidance. Let's merge this in :-) |
Signed-off-by: Heitor Lessa <[email protected]>
My suggestion:
Hey @neilramsay, I owe you an additional explanation about straight comments I've made. I'd also like to explain our reasoning about our obsession with docs and shorter message, as perhaps that might be useful to learn our techniques too :) About minimal comments We have a daily standup to review our activities in the public board. Yesterday, we were reviewing the last pending items to merge it and I commented live as we spoke on suggestions to @leandrodamascena - hence why this short suggestion. Our take on documentation We approach documentation like a product. We're not yet where we'd like to be, but we take each PR as an opportunity to make our messaging accessible, shorter, and more easily readable in different formats (e.g., Mobile). We see documentation as a large reason for customers to use Powertools for the long-term, besides features, bug fixing, and how we work with the community. We also have an incredibly plurality of personas - from Developers, IT hobbyists, Data Engineers, Ops ("DevOps"), SRE, Data Scientists, Mobile engineers, Embedded engineers, etc - and from various spoken languages, where Global English style is a must.
This means we always strike a balance to deliver the message as straight as possible, then provide more info for anyone wanting to know the nitty gritty details. All carefully thinking about mobile readers where text may be wrapped. This, sometimes counterintuitive, pushes us to use shorter but more paragraphs that typically would be merged under different circumstances. Now that we're on the same page This is the process we would then follow by working backwards from your second suggestion:
Questions we asked ourselves:
We then craft a rather verbose message and then ask two more questions:
For the first one we use a technique called Line Editing. For the second one, it's a combination of us having English as a Second Language (ESL) and using that to our advantage to see how much of a cognitive load it takes to parse the text before we can grasp it. Combine this scrutiny, we landed at:
Which meant:
Closing That's why it's a great deal for us to take however as much time we need to give feedback to anyone contributing it, so they get something back too! We hugely appreciate the effort you've made to improve debugging - it's not everyone who takes hours off their time to improve many hours of many many people out there. Hope this provides more than enough context on terseness at times, and explain our mental model when dealing with docs ;) |
@heitorlessa thank you very much for the documentation explanation. I believe others could benefit from this guidance, so will raise a new Issue suggesting some sort of "advanced meta-documentation", and linking it here. |
Issue number: #2128
Summary
Allow Data Classes to be printed with
str()
Changes
User experience
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
__str__
isn't implemented elsewhere for Data Classes in the library, so shouldn't impact the library.I assume most people wouldn't deliberately print the class name, and memory location for debugging/troubleshooting, so shouldn't impact them.
One area where I need assistance is noting what properties throughout the Data Classes should be blacklisted.
RFC issue number:
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.