Regression in Fields marked Optional
I've identified another regression between Lift 2.0/2.1-M1 and Lift 2.1-RC1/RC2.
Given the following code:
Under Lift 2.0 and Lift 2.1-M1, you get the following (expected) behavior:
The "name" field is optional_?=true and has been set to be Empty, so it is excluded from the DBObject.
Under Lift 2.1-RC1 and Lift 2.1-RC2, you get the following (unexpected) behavior:
The "name" field is still optional_?=true and set to Empty, but now the DBObject includes the "name" field with an empty string (the default value).
I suspect this has to do with the toValueType/toBoxMyType roundtrip in TypedField, but I'm not sure and I do not have a fix yet.
Given the following code:
import net.liftweb.common._
import net.liftweb.mongodb.record._
import net.liftweb.record.field._
class SimpleUser extends MongoRecord[SimpleUser] with MongoId[SimpleUser] {
override def meta = SimpleUser
object name extends StringField(this, 50) {
setBox(Empty)
override def optional_? = true
}
}
object SimpleUser extends SimpleUser with MongoMetaRecord[SimpleUser] {
override def createRecord = new SimpleUser // This line needs to be commented out to compile under Lift 2.1-RC1/2
}
Under Lift 2.0 and Lift 2.1-M1, you get the following (expected) behavior:
scala> SimpleUser.createRecord.asDBObject
res0: com.mongodb.DBObject = { "_id" : { "$oid" : "4c93df29cd1395091868b217"}}
The "name" field is optional_?=true and has been set to be Empty, so it is excluded from the DBObject.
Under Lift 2.1-RC1 and Lift 2.1-RC2, you get the following (unexpected) behavior:
scala> SimpleUser.createRecord.asDBObject
res0: com.mongodb.DBObject = { "name" : "" , "_id" : { "$oid" : "4c93dd3f09b0950958646c6e"}}
The "name" field is still optional_?=true and set to Empty, but now the DBObject includes the "name" field with an empty string (the default value).
I suspect this has to do with the toValueType/toBoxMyType roundtrip in TypedField, but I'm not sure and I do not have a fix yet.
Leave a comment
on 2010-09-17 18:00 *
By jorgeortiz85
Description changed from I've identified another reg... to I've identified another reg...
on 2010-09-17 18:01 *
By jorgeortiz85
Description changed from I've identified another reg... to I've identified another reg...
Pushed:
http://github.com/lift/lift/commit/39d1df84e9f3ca15cd65f78e64979edcd11886ff for 2.x-2.7_devel
http://github.com/lift/lift/commit/47247d91bfbfe539b170f1cc26d54b8ab8e9febd for 2.x-2.8_devel
http://github.com/lift/lift/commit/39d1df84e9f3ca15cd65f78e64979edcd11886ff for 2.x-2.7_devel
http://github.com/lift/lift/commit/47247d91bfbfe539b170f1cc26d54b8ab8e9febd for 2.x-2.8_devel