improvement: include context in inspect consistently #2441
+41
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contributor checklist
Description
This came up when I was debugging (using
dbg()) why my scope wasn't correctly propagated ascontextin my project. It took me a while to figure out that it was indeed correctly propagated but callingdbg(query)does not show whether or not there's a context or its contents.My goal here is to save my future self and everyone else the time and frustration by putting the context into the
Inspectimplementation.Design Decisions
When I asked Zack if I could simply add it he was cautious and said it had been intentionally left out due to concerns about leaking sensitive data. A very valid concern given that
inspectis often used for logging.My primary goal is to show that there is a (non empty) context present, not necessarily what its contents are. If the content is important you can look at it by directly calling
dbg(query.context)in any case.There is already a config setting called
:show_sensitive?which is used by theAsh.Helpers.redact/1function. I'm using this function if the context is non empty so it will show up ascontext: "**redacted**"by default, which gives enough of a clue that there is something present without potentially leaking something sensitive.With the setting enabled it embeds the context as expected.
Current Implementation and Consistency
While writing this PR I looked at other entities which are passed to callbacks and carry the context inside and how they handle inspect (mostly
Ash.ChangesetandAsh.ActionInput).As far as I can tell there is no consistent logic being applied. For example one implementation removes the
:privatkey from context but embeds it without redacting anything. The one inAsh.Queryomits it fully and inAsh.ActionInputthere's no customInspectso it seems to just show everything as it is.I don't want to stray too far from my original goal but if you think it's worthwhile to have a consistent logic behind all of these structs, then we can discuss what the "spec" looks like and I'll try to implement that.
What I've tried to implement so far is this:
Structs passed to callbacks which contain a
:contextmap shouldcontextin theirInspectoutput if the context is emptycontext: "**redacted**"if the context is non empty if:show_sensitive?is false (default)context:with all keys except:privateembedded if:show_sensitive?is trueAsh.Helpers.redact/1where applicable for the aboveSorry for the wall of text and thanks for reading it anyway! 😄
References