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

The <property /> definition for column type does not work in version 4.6.1, which works well in 3.x.x #2231

Closed
JosephCen opened this issue Nov 23, 2021 · 9 comments · Fixed by #2351
Assignees
Milestone

Comments

@JosephCen
Copy link

Environment

Mac OS, postgres-12

Liquibase Version: 4.6.1

Liquibase Integration & Version: spring boot

Liquibase Extension(s) & Version: <n/a>

Database Vendor & Version: postgres-12 in container 'postgres:12-alpine'

Operating System Type & Version: Mac OS

Description

An exception java.lang.ArrayIndexOutOfBoundsException happened when run with below change log.

<databaseChangeLog ...>

    <property name="bytesarray_type" value="BYTEA" global="false" dbms="postgresql" />

    <changeSet author="i521084" id="1583641912012-4">
        <createTable tableName="asyncevent">
            <column name="id" type="BIGINT">
                <constraints primaryKey="true" primaryKeyName="asyncevent_pkey"/>
            </column>
            <column name="messagebodybytes" type="${bytesarray_type}"/>
            <!-- ... -->
        </createTable>
    </changeSet>
</databaseChangeLog>

I think the root cause is that defined <property /> is not parsed well when Liquibase handle above change log. Then a column with type ${bytesarray_type} is passed to following logic and result an 'ArrayIndexOutOfBoundsException' thrown at below code line.

DataTypeFactory

Steps To Reproduce

  1. Using postgres DB in docker image 'postgres:12-alpine'.
  2. Using a changelog as above.
  3. Run the changelog with 'liquibase.integration.spring.SpringLiquibase.performUpdate'.
  4. The exception will happened with handle above 'create table' change set.

Actual Behavior

An exception ArrayIndexOutOfBoundsException happened.

Expected/Desired Behavior

Relevant table should be created with above change log. And the same change log works well under Liquibase version 3.x.x.

Screenshots (if appropriate)

Exception call stack:
image

Additional Context

We just follow below document create relevant change log and there is no update against below Liquibase document.
https://docs.liquibase.com/concepts/basic/changelog-property-substitution.html

@molivasdat
Copy link
Contributor

Hi @JosephCen Thanks for writing up this issue. I think the problem may be more around the byte array definition that in the property substitution. To validate change your property value to TEXT or some other know column type and if it works then we are down to the bytearray type. If it does not work, then it may be around property substitution.

@JosephCen
Copy link
Author

@molivasdat After more investigate, I found the issue will be reproduce when there are more than 1 <property /> definition for more than one dbms.

<databaseChangeLog ...>

    <property name="bytesarray_type" value="BYTEA" global="false" dbms="postgresql" />
    <property name="bytesarray_type" value="BYTEA" global="false" dbms="oracle" />

    <changeSet author="i521084" id="1583641912012-4">
        <createTable tableName="asyncevent">
            <column name="id" type="BIGINT">
                <constraints primaryKey="true" primaryKeyName="asyncevent_pkey"/>
            </column>
            <column name="messagebodybytes" type="${bytesarray_type}"/>
            <!-- ... -->
        </createTable>
    </changeSet>
</databaseChangeLog>

But the reason why <property /> is used is that we want to support more than one dbms with one changeSet.

@JosephCen
Copy link
Author

@molivasdat @wwillard7800 I guess I found the reason why this issue will happen.
Please refer below commit:
e157992

My question is why we need to remove duplicate key property. As you know that these 2 properties may have different dbms setting.

@molivasdat
Copy link
Contributor

molivasdat commented Jan 10, 2022

Hi @JosephCen Thanks for the feedback. We are checking into this.

@JosephCen
Copy link
Author

JosephCen commented Jan 11, 2022

@molivasdat Thanks for quick reply. I just added some comment in relevant PR. Please take a look. BTW, whether there is a SNAPSHOT version I can get and test at my work machine when you finish the fix.

@nvoxland
Copy link
Contributor

@JosephCen there are snapshot builds that get attached to each PR. If you click on the "checks" tab at the top, you can get to the most recent build which has them.

There are a few artifacts. The one named liquibase-zip-<BRANCH> is what would come in the liquibase.zip artifact.

@nvoxland nvoxland added this to To Do in Conditioning++ via automation Jan 13, 2022
@nvoxland nvoxland moved this from To Do to Code Review in Conditioning++ Jan 13, 2022
@JosephCen
Copy link
Author

@nvoxland I am afraid that I still do not get the place for download the liquibase-core.jar for this current PR.
I want to get the *.jar to test it at my local side.

@suryaaki2 suryaaki2 moved this from Code Review to Ready for Handoff (In JIRA) in Conditioning++ Jan 21, 2022
@kataggart kataggart assigned nvoxland and unassigned wwillard7800 Feb 1, 2022
@nvoxland
Copy link
Contributor

Sorry for the slow reply @JosephCen

We're working on a more direct way to get the artifacts, but you can get it from https://github.com/liquibase/liquibase/pull/2351/checks which has an "artifacts" link/dropdown on the top.

In there is liquibase-zip-fix_for_GH_2231 which is what you'd download as liquibase.zip.

@XDelphiGrl XDelphiGrl assigned XDelphiGrl and unassigned nvoxland Feb 15, 2022
@XDelphiGrl
Copy link
Contributor

This bug reproduces if the JDBC URL matches the dbms provided in the first property in a set of changelog properties. Specifically, given a changelog like:

http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.0.xsd">
 
	<property name="bytesarray_type" value="BYTEA" global="false" dbms="postgresql" />   
	<property name="bytesarray_type" value="BLOB" global="false" dbms="mysql" />

	
	<changeSet author="liquibase" id="1::noDBMSPropertyInChangeSet">
        <createTable tableName="pr2231">
            <column name="id" type="BIGINT">
                <constraints primaryKey="true" primaryKeyName="pr2231_pkey"/>
            </column>
            <column name="messagebodybytes" type="${bytesarray_type}"/>
        </createTable>
    </changeSet>
	
</databaseChangeLog>
  • When I run liquibase update with a Postgres JDBC connection like url: jdbc:postgresql://localhost:5433/goku I get the array out of bounds error.
  • When I run liquibase update with a MySQL JDBC connection like url: jdbc:mysql://localhost:3309/testdb1?useSSL=false&allowPublicKeyRetrieval=true, I do not get the error.

When I swap the order of the properties in my changelog, I no longer get an error connecting with Postgres but do get the error connecting with MySQL.


  • Verify a successful update using a changelog with multiple changelog properties and no dbms on changesets. PASS
First DBMS Property Global JDBC Substituted Type Update P/F
postgresql false postgresql BYTEA P
postgresql false mysql BLOB P
postgresql true postgresql BYTEA P
postgresql true mysql BLOB P
mysql false mysql BLOB P
mysql false postgres BYTEA P
  • Verify successful update using a changelog with multiple changelog properties and dbms on changesets. PASS
First DBMS Property Changeset DBMS JDBC Substituted Type Update P/F
postgresql postgresql postgres BYTEA P
mysql postgresql postgres BYTEA P
postgresql mysql mysql BLOB P
mysql mysql postgres NONE (no match) P (nothing to deploy)
  • Verify there is no regression in fix for GH Issue. PASS
    • Internal functional regression test passes PASS

Test Environment
Liquibase Core: fix_for_GH_2231/1449/16c1ec, Pro: master/591/f653ec
Postgres 12.6
MySQL 8
Windows 10
Functional Tests

  • The functional tests have failures in in Pro licensing validation; this has no impact on Community.
  • I see no reason to hold this ticket from merging due to those failures.
  • The automated regression test associated with a previous bug that accidentally introduced this bug still passes when I run it locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

6 participants