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

Investigate what we can do to prevent required misalignment #148

Open
untitaker opened this issue May 26, 2023 · 0 comments
Open

Investigate what we can do to prevent required misalignment #148

untitaker opened this issue May 26, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@untitaker
Copy link
Member

untitaker commented May 26, 2023

We have a schema definition with two fields, foo_required and foo_optional.

{"properties": {"foo_required": {}, "foo_optional": {}}, "required": ["foo_required"]}

Now consider this code:

x["foo_optional"]

VSCode/pyright does error on the above line because it might crash. Unfortunately, mypy does not.

We had an incident (without incident ticket) where this exact crash happened:
c19ad27

This schema change added a new, optional field, but the corresponding Snuba PR accessed the field as if it was required. Mypy did not catch this.

When we merged the Snuba PR, sentry CI failed because the field wasn’t being sent to snuba, so snuba crashed. Technically there were multiple problems:

  1. schema validation was missing in some places on producer side

  2. even if the schema was validated on producer side, the field was optional according to it

  3. on the snuba side, the misalignment between consumer and schema was not caught due to the above mypy bug

We should focus on (3) for this ticket. If the field was marked as required in the schema, our existing PR linting would’ve at least told the user that this was a breaking change.

Proposed solution

see jsonschema-gentypes issue

(also tracked as SNS-2325, see also mypy issue)

@untitaker untitaker added the bug Something isn't working label May 26, 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
Projects
None yet
Development

No branches or pull requests

1 participant