Menu

#363 Regression: cannot insert an empty string

v2.5.*
closed-fixed
None
2.5.1
5
2016-04-26
2014-06-11
No

I have some entries in a dataset where I want the value of a column to be set to an empty string:

<configuration node_group="EIT" level="0" level_name="" config_key="player.allowAnonymous" value="false"/>

This worked in 2.4.9, but in 2.5.0 I get:

Caused by: java.lang.IllegalArgumentException: table.column=configuration.level_name value is empty but must contain a value
    at org.dbunit.operation.AbstractBatchOperation.handleColumnHasNoValue(AbstractBatchOperation.java:251)
    at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:195)
    at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:79)

Discussion

  • Jeff Jensen

    Jeff Jensen - 2014-06-16

    This is a deliberate change, not a bug. It illuminates test data problems. Other errors can occur due to this and users don't understand it. From the changes report: http://dbunit.sourceforge.net/changes-report.html#a2.5.0: "Fail fast and clearly when column value has no value; throws IllegalArgumentException."

    To have null values in fields, make a replacement object "[NULL]" that maps to a Java null and use ReplacementDataSet.

    Consider using DataFileLoader implementations, such as FlatXmlDataFileLoader, to make it easier.

    These pages describe:
    http://dbunit.sourceforge.net/howto.html
    http://dbunit.sourceforge.net/components.html

    If you do not like this behavior change, please create a feature request and attach a patch with tests to create a property that enables/disables it and defaults to enabled.

     
  • Jeff Jensen

    Jeff Jensen - 2014-06-16
    • status: open --> closed-invalid
    • assigned_to: Jeff Jensen
     
  • Rich DiCroce

    Rich DiCroce - 2014-06-17

    I'm not trying to insert a null value, I'm trying to insert an empty string. In other words, the value in the database should be '', not NULL.

    After looking at the source code for AbstractBatchOperation, I don't see how a ReplacementDataSet would help. I could use a value like '[empty]' in the XML dataset and replace it with '', but that still means the value that AbstractBatchOperation gets will be '', unless I'm missing something.

     
  • Jeff Jensen

    Jeff Jensen - 2014-06-17
    • status: closed-invalid --> open
     
  • Jeff Jensen

    Jeff Jensen - 2014-06-17

    :-/ yes, you are correct, using something like "[EMPTY]" would not work.

    Do you have time to add a new feature flag that enables/disables it and defaults to enabled with tests? Can then change the new AbstractBatchOperation check to something like:
    if (value == "" && !allowEmptyFields)

    If so, update the DatabaseConfig class and obtain the allowEmptyFields value from it.

     
  • Rich DiCroce

    Rich DiCroce - 2014-06-18

    I'll try to get to this soon, but I can't make any promises.

     
  • Jeff Jensen

    Jeff Jensen - 2014-06-18

    :-) I'll do it at some point. Your option if you need the change sooner than I get to it.

     
  • Bart Van Remortele

    This is very important, in our case we want to perform a test for empty string columns.

     
  • Leonardo D'Alimonte

    We have the same issue here integrating our project with new version 2.5.0.
    As a workaround, I was thinking to override the method responsible that throws IllegalArgumentException..

     
  • Bustuila

    Bustuila - 2014-10-10

    The weird thing is that because of this issue the dataset generated by dbunit cannot be loaded back.

     
  • Adam Siemion

    Adam Siemion - 2014-10-15

    I have experienced the same problem as @Bustiula. Exported data from MySQL and wanted to load it in H2 and run into this problem as the MySQL database had NOT NULL columns with empty string values. I will switch to 2.4.9, if I have time I will work on the patch.

     

    Last edit: Adam Siemion 2014-10-15
  • Adam Siemion

    Adam Siemion - 2014-10-19

    I have implemented the new "allowEmptyFields" feature that Jeff mentioned in one of his comments in this thread. It defaults to "false" to not alter the current behavior. It is accompanied by extensive (I think) tests for both inserts and updates. Feel free to let me know if you want me to make any changes in the patch.

     
    • Jeff Jensen

      Jeff Jensen - 2014-11-29

      Excellent patch Rich! Thank you very much for doing it. Applied.

       
  • Robert Bräuning

    This bug causes also problems in our tests, where an empty string is really commmon and not indicates wrong testdata!
    I would appreciate a quick fix, because extending InsertOperation to overide the handleColumnHasNoValue Method won't work, due to the protected constructor :-/
    The only possibility I see right now, is to extend AbstractOperation and copy all the code from InsertOperation --> doesn't sound good to me :-(

     
  • Adam Siemion

    Adam Siemion - 2014-11-17

    Robert, you can use the patch I have attached in the previous comment. Just apply it the latests sources and build dbunit.

     
  • Robert Bräuning

    Thanks for your quick reply, Adam. That's unfortunately no option for me, because our project is part of a pretty big enterprise application and all dependencies to third party libraries are configured centrally. So I think it's more likely to change the version to 2.4.9 than to "customize" dbunit. ;-)

     
  • Jeff Jensen

    Jeff Jensen - 2014-11-29

    Ticket moved from /p/dbunit/bugs/356/

    Can't be converted:

    • _fixed_release: (not fixed)
    • _milestone: v2.5.*
     
  • Jeff Jensen

    Jeff Jensen - 2014-11-29

    Ticket moved from /p/dbunit/feature-requests/186/

    Can't be converted:

    • _milestone: v2.5.*
     
  • Jeff Jensen

    Jeff Jensen - 2014-11-29
    • status: open --> closed-fixed
    • Fixed Release: --> 2.5.1
     
  • Jeff Jensen

    Jeff Jensen - 2014-11-29

    I deployed 2.5.1-SNAPSHOT to dbUnit's snapshot repository [0] containing Adam Siemion's patch with the new allowEmptyFields config for anyone that can try it, verifying no problems before releasing with it.

    [0] (See http://dbunit.sourceforge.net/repos.html if you don't know where that is!)

     

Log in to post a comment.