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

Enforce custom type keys are lowercase #47

Merged
merged 5 commits into from
Mar 22, 2023

Conversation

sldblog
Copy link
Contributor

@sldblog sldblog commented Mar 20, 2023

A creator was unable to delete an image which was part of a custom type with a name like meetTheCard. The cause was a type mismatch caused by downcasing. We opted to enforce consistent casing.

To ensure integrity across all layers, we want to enforce lowercase keys at the point of custom type validation.

Decisions

  • Should we change block_schema_spec?
  • Should we change menu_schema_spec?
  • Should we change schema_attribute_spec?

Answer to the above: No: we already treat built-in types as case insensitive, which would be too impactful to change. Keeping the type name validation scoped to custom types looks safe.

Consequences

  • We will manually fix custom types with uppercase letters (there are 4 of them).

  • All three current themes pass this new rule ✅

  • This will hook into the validation of custom types on the UI: image

  • Also when linting a theme: image

Co-authored-by: @eballantine

sldblog and others added 2 commits March 20, 2023 16:07
Co-authored-by: Lizzy Ballantine <lizzy.kayballantine@gmail.com>
We are adding another one soon

Co-authored-by: Lizzy Ballantine <lizzy.kayballantine@gmail.com>
@sldblog sldblog requested review from a team, ianmooney and eballantine and removed request for a team March 20, 2023 16:43
@sldblog sldblog marked this pull request as draft March 20, 2023 16:53
@sldblog sldblog force-pushed the add-validation-against-key-casing branch from dbd055a to 100457d Compare March 21, 2023 11:27
@sldblog sldblog marked this pull request as ready for review March 21, 2023 11:39
@sldblog
Copy link
Contributor Author

sldblog commented Mar 21, 2023

@sldblog sldblog added the bug Something isn't working label Mar 21, 2023
@ianmooney ianmooney self-assigned this Mar 22, 2023
Copy link
Contributor

@ianmooney ianmooney left a comment

Choose a reason for hiding this comment

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

Lovely stuff 👌

Copy link
Member

@geoffreymm geoffreymm left a comment

Choose a reason for hiding this comment

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

Nice one! My only feedback is around ensure we highlight (on the commit message and not only on the PR description) that this behaviour is just enforced for custom type definition and not across all blocks, menus and so on that do have a schema definition too. Hope this makes sense.

@@ -38,6 +38,7 @@ def validate
ensure_has_required_keys &&
Copy link
Member

Choose a reason for hiding this comment

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

Could we add to the commit message that this behaviour is for the schema definition of the custom types and not "all possible schemas"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally!

Better commit message in 029509e
Explicit case insensitive matching validation in 8dc241a

@geoffreymm geoffreymm self-assigned this Mar 22, 2023
sldblog and others added 3 commits March 22, 2023 11:55
We store custom types in the database with a requirement to have keys
unique within a theme.

This validation is case sensitive; currently, it's possible to create
multiple version of the same type with names like `type` and `Type`.

Changing this validation to case insensitive in the persistence layer
could lead into themes failing to load custom types in the future. (Now
it's guaranteed to be unique as the first time load from the theme
creates the first custom types.)

To ensure integrity across all layers, we want to enforce lowercase keys
at the point of custom type validation.

Co-authored-by: Lizzy Ballantine <lizzy.kayballantine@gmail.com>
To guarantee interoperatibility with current attribute and block
schemas, ensure that custom type lookup for validation is case
insensitive.
Due to incompatible key validation changes

Co-authored-by: Lizzy Ballantine <lizzy.kayballantine@gmail.com>
@sldblog sldblog force-pushed the add-validation-against-key-casing branch from 100457d to 54982c4 Compare March 22, 2023 12:20
@sldblog sldblog requested a review from geoffreymm March 22, 2023 12:22
Copy link
Member

@geoffreymm geoffreymm left a comment

Choose a reason for hiding this comment

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

Amazing!

@sldblog sldblog merged commit c3f4ee6 into main Mar 22, 2023
@sldblog sldblog deleted the add-validation-against-key-casing branch March 22, 2023 12:35
@sldblog sldblog changed the title Enforce schema definition keys are lowercase Enforce custom type keys are lowercase Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

3 participants