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: add versioning for trigger encoding #2561

Merged
merged 3 commits into from
May 23, 2023

Conversation

schoren
Copy link
Collaborator

@schoren schoren commented May 22, 2023

This PR fixes a retrocompat issue, where tests created before this version would fail to be correctly read from DB. This was caused by a change in the JSON encoding of the model.Trigger entity.

This PR fixes this by adding basic versioning support for the entity

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

if err != nil {
return err
}
if v2.valid() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it expected to fail silently (returning nil) if both .valid() methods return false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. I added an error here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, this breaks a lot of things where the triggers are not completely defined, like tests with empty triggers.

The error should be returned if there's a problem parsing the json string, like invalid characters etc. The valid method is only here to check if the versions match, but if no version match, it doesn't mean that the JSON is invalid.

Since we cannot accurately detect the difference between an incompatible encoding and an actual error, doing so mixes unmarshalling and validation, and it's not even a solid validation.

The situation where we fail to unmarshall valid data should only happen during development, and mainly when working with encodings (as this PR does). So, failing silently is probably not THAT bad.

@schoren schoren merged commit 02ede47 into feat/transactions-as-resources May 23, 2023
@schoren schoren deleted the fix-trigger-retrocompat branch May 23, 2023 03:09
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.

3 participants