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(Sync): Do not show conflicts for empty keys #7556

Conversation

gatzjames
Copy link
Contributor

@gatzjames gatzjames commented Jun 17, 2024

Highlights:

  • New keys in models should be optional

Problem:

  • Currently when we check the status of candidates we get an object from the database.
  • The database query functions initialize the model and add any new keys even if they are empty (undefined/empty string/null).
  • Empty keys (e.g. empty string) can also be the desired state that needs to be commited in case a user updates a value like that.

e.g.
Previous version of object:

{
   "id": "1",
}

New version of object:

{
  "id": "1",
  "newProp": undefined
}

This should not show up in changes that need to be commited.

Approaches Tested:

  • Use the VCS to compare against the previous version of an object.

    • If the previous version doesn't have a key and the new version contains an empty value for that key then it won't appear as a changed property in the status diff.
  • Only update properties of objects in the database if the value of a key is not empty for keys that have a default undefined value

  • Only handle this for new keys. New keys can be defined as optional.

Comparison between the two approaches:

VCS (Compare against previous version) DB (only update keys that are optional if they have a value) Models (New keys should be optional and default to undefined)
Doesn't rely on undefined values on the initial model Relies on undefined values on the initial model Relies on new keys defaulting to undefined
Works for any kind of diff that happens between two versions of an object. If the previous version doesn't contain a key and the new version has an empty value* there will not be any changes Only works for keys that are specified as undefined in the initial model and only for when we call the database.update method. Works for all objects
Requires getting the previous version of the document using a specific method for VCS (different between Insomnia Sync and Git Sync) Works with all types of VCS since it only relies on DB models Works for all types of VCS
TBD how this works with a previous version of the app pulling and pushing changes TBD how this works with a previous version of the app pulling and pushing changes ✅ Tested with previous versions

✅ After discussion with the team we decided to go with the last approach: Models (new keys should be optional and default to undefined)

@gatzjames gatzjames self-assigned this Jun 17, 2024
@gatzjames gatzjames requested a review from a team June 17, 2024 13:31
@gatzjames gatzjames force-pushed the feature/ins-3990-do-not-commitpush-new-empty-fields branch from cfdc831 to 3df24ed Compare June 18, 2024 10:58
@gatzjames gatzjames changed the title fix(Sync): Do not compare unused keys fix(Sync): Do not show conflicts for empty keys Jun 18, 2024
@gatzjames gatzjames force-pushed the feature/ins-3990-do-not-commitpush-new-empty-fields branch from dd47441 to d0b69ad Compare June 18, 2024 11:14
@gatzjames gatzjames force-pushed the feature/ins-3990-do-not-commitpush-new-empty-fields branch from 9fe5d03 to 1c37535 Compare June 19, 2024 13:23
@gatzjames gatzjames marked this pull request as ready for review June 19, 2024 13:23
Comment on lines +271 to +273
const stringifiedData = JSON.stringify(data);
if (format.toLowerCase() === 'yaml') {
return YAML.stringify(data);
return YAML.stringify(JSON.parse(stringifiedData));
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks like it might be a regression

@gatzjames gatzjames merged commit 42bda02 into Kong:develop Jun 19, 2024
7 checks passed
@gatzjames gatzjames deleted the feature/ins-3990-do-not-commitpush-new-empty-fields branch June 19, 2024 13:59
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.

None yet

2 participants