Skip to content

Conversation

danielthegray
Copy link
Contributor

@danielthegray danielthegray commented May 6, 2021

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.)
  • 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

@molivasdat
Copy link
Contributor

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.

@asomov
Copy link
Contributor

asomov commented Dec 27, 2022

@danielthegray SnakeYAML has a property to prohibit the same keys

@danielthegray danielthegray force-pushed the prevent-double-databasechangelog-tags branch from 52dce37 to da61869 Compare May 6, 2024 17:41
@danielthegray danielthegray force-pushed the prevent-double-databasechangelog-tags branch from da61869 to fd33644 Compare May 6, 2024 17:46
@danielthegray danielthegray force-pushed the prevent-double-databasechangelog-tags branch from fd33644 to 8af7e84 Compare May 6, 2024 17:51
@daniel-gray-jemmic
Copy link

@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?

@filipelautert
Copy link
Collaborator

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

@filipelautert filipelautert self-assigned this May 7, 2024
@danielthegray danielthegray force-pushed the prevent-double-databasechangelog-tags branch from 8af7e84 to 83c3977 Compare May 16, 2024 12:04
@danielthegray danielthegray force-pushed the prevent-double-databasechangelog-tags branch from 83c3977 to b161673 Compare May 23, 2024 17:11
@danielthegray danielthegray force-pushed the prevent-double-databasechangelog-tags branch from b161673 to 64fd85e Compare May 23, 2024 18:24
@danielthegray danielthegray force-pushed the prevent-double-databasechangelog-tags branch from 64fd85e to bb26acb Compare May 24, 2024 10:25
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.
@danielthegray danielthegray force-pushed the prevent-double-databasechangelog-tags branch from bb26acb to c7eacc6 Compare May 27, 2024 08:20
@filipelautert filipelautert merged commit 323b1b9 into liquibase:master May 29, 2024
@filipelautert filipelautert added this to the 1NEXT milestone May 29, 2024
@danielthegray danielthegray deleted the prevent-double-databasechangelog-tags branch May 30, 2024 13:07
MalloD12 added a commit that referenced this pull request May 30, 2024
@MalloD12
Copy link
Collaborator

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 added a commit that referenced this pull request May 31, 2024
…asechelog tags (#5962)

* Create UnparsedSql object specifying endDelimiter value.

* Undo changes of #1826 to avoid having issues with duplicated sql tags with yaml format changelogs.
@danielthegray
Copy link
Contributor Author

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?

@filipelautert
Copy link
Collaborator

filipelautert commented Jun 3, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

9 participants