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 mixed context key types on reify #393

Merged
merged 2 commits into from
Feb 20, 2023

Conversation

cap10morgan
Copy link
Contributor

I found I needed this for my additional tests in http-api-gateway to pass. Builds on #392 so we should discuss that first.

@cap10morgan cap10morgan requested a review from a team February 17, 2023 19:04
context))
(if (= :keyword context-type)
context
(keywordize-keys context)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sort of confused about this, keywordize-keys already checks if keys are a string. Is this just meant to save that work when it's known to be unnecessary?

And the breakage here was because we were skipping out on keywordization when we shouldn't have?

Sort of feels weird to me to have an implicit enum of context types (keyword or string), but we just sometimes violate that by having no context type (or do they sometimes end up mixed?), and then we have two runtime-check-style fns to clean things up.

(Not a blocker for merging this, more just thinking out loud/trying to make sure I understand.)

Copy link
Contributor Author

@cap10morgan cap10morgan Feb 20, 2023

Choose a reason for hiding this comment

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

Yeah we could just always call keywordize-keys but if :context-type :keyword is set (the default) then it should be unnecessary.

The case where we have no context-type is when we're reifying from storage. So it's a side effect of these functions be used in two rather different scenarios:

  1. A user is creating a ledger for their own use and supplies a context-type or gets the default of :keyword.
  2. We are internally reloading an existing ledger from storage. We have full control over the context in this case, so we could, in theory, make it always strings or always keywords and set the context-type explicitly.

I just seem to keep playing mixed-keyword-and-string-keys whack-a-mole in here. So trying to balance that against not doing more work than is necessary. Definitely an area for additional cleanup / refactoring.

@cap10morgan cap10morgan merged commit f64bd97 into main Feb 20, 2023
@cap10morgan cap10morgan deleted the fix/mixed-context-key-types-on-reify branch February 20, 2023 19:26
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.

2 participants