liquibase icon indicating copy to clipboard operation
liquibase copied to clipboard

Prevent silent failures when two "databaseChangeLog" tags are present

Open danielthegray opened this issue 3 years ago • 4 comments

Environment

Liquibase Version: all

Liquibase Integration & Version: all

Liquibase Extension(s) & Version: all

Database Vendor & Version: all

Operating System Type & Version: all

Pull Request Type

  • [ ] Bug fix (non-breaking change which fixes an issue.)
  • [x] Enhancement/New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Description

If someone makes a mistake and copy/pastes a databaseChangeLog block in, and makes the file have two tags, the SnakeYAML parser silently covers up the first instance with the second one, which will cause the first block of changes to be silently omitted.

This can be very problematic and cause hard-to-debug errors, which is why I have added a small FilterInputStream interceptor to check the stream as it is fed into the YAML parser, for a duplicate tag. Doing it with the FilterInputStream like this prevents the efficiency losses of opening the file twice.

Steps To Reproduce

You can look at the added test; essentially, just create a changelog file which has two "databaseChangeLog" tags.

Actual Behavior

It will silently to the wrong thing (i.e. skip over the first group of changesets).

Expected/Desired Behavior

An error should be thrown to highlight the fact that there are two databaseChangeLog tags/keys.

Fast Track PR Acceptance Checklist:

Need Help?

Come chat with us on our discord channel

danielthegray avatar May 06 '21 16:05 danielthegray

Hi @danielthegray Thanks for the improvement in the use of Liquibase. It is much appreciated.

Here's what happens next: A member of the Liquibase team will take a look at your contribution and may suggest:

The PR will be prioritized according to our internal development and testing capacity.

We’ll let you know when it’s ready to move to the next step or if any changes are needed.

molivasdat avatar May 07 '21 13:05 molivasdat

@danielthegray SnakeYAML has a property to prohibit the same keys

asomov avatar Dec 27 '22 09:12 asomov

@danielthegray SnakeYAML has a property to prohibit the same keys

Thank you @asomov for the great tip, it greatly simplifies the code! I've pushed a new revision of the branch with conflicts resolved, but the "FOSSA License Compliance and Security Check" is failing. Does something need to be added to the branch code?

daniel-gray-jemmic avatar May 06 '24 17:05 daniel-gray-jemmic

@daniel-gray-jemmic currently fossa is failing for contributed PR's, don't worry about it.

filipelautert avatar May 06 '24 18:05 filipelautert

Hi @daniel-gray-jemmic,

I just wanted to let you know today I commented out the line you added on the YamlParser class, plus ignored the test you also added in this PR because this change was breaking the case of having a duplicate sql: property. I created the issue #5963 in order to fine a way to keep using your code change, but without breaking some other case like the one mentioned in that issue.

If you have any ideas or would like to work on it, please feel free to assign it to yourself or ask any questions/concerns you might have.

Thank you and apologies for this, Daniel.

MalloD12 avatar May 30 '24 22:05 MalloD12

Hi, I understand. The first commit I had on this issue was ONLY detecting the duplicate databaseChangeLog, and I changed it to the duplicate flag because of a suggestion in a comment on this thread. Should we try to revert to the previous version instead?

danielthegray avatar Jun 03 '24 15:06 danielthegray

Hi, I understand. The first commit I had on this issue was ONLY detecting the duplicate databaseChangeLog, and I changed it to the duplicate flag because of a suggestion in a comment on this thread. Should we try to revert to the previous version instead?

@danielthegray I think this would be a better approach, thanks!

filipelautert avatar Jun 03 '24 18:06 filipelautert