← Back to team overview

touch-packages team mailing list archive

[Bug 1215898] Re: Strange behaviour with multiple elements on first level in contents

 

** Branch linked: lp:~ubuntu-branches/ubuntu/utopic/u1db-qt/utopic-
proposed

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to u1db-qt in Ubuntu.
https://bugs.launchpad.net/bugs/1215898

Title:
  Strange behaviour with multiple elements on first level in contents

Status in U1DB Qt/ QML:
  Fix Committed
Status in “u1db-qt” package in Ubuntu:
  Fix Released

Bug description:
  I recognized some very strange behaviours concerning multiple elements
  on the first level in "contents" of a document. Here is what I managed
  to reproduce:

  The example http://bazaar.launchpad.net/~uonedb-qt/u1db-
  qt/trunk/view/head:/examples/u1db-qt-example-5/u1db-qt-example-5.qml
  normally produces a ListView like this:

  (0) 'Hello World 1'
  (1) 'Hello World 2'
  (2) 'Hello World 2.5' 
  (3) 'Hello World 3'
  (4) 'Hello World 3.33'
  (5) 'Hello World 3.66'


  If I now change the structure to have both "message" and "id" as a
  first level element, like this:

  U1db.Document {
              database: aDatabase
              docId: 'helloworld1'
              create: true
              defaults: { "message":"Hello World", "id": 1 }

          }

         U1db.Document {
              database: aDatabase
              docId: 'helloworld2'
              create: true
              defaults: { "message":"Hello World", "id": 2 }
          }

         U1db.Document {
              database: aDatabase
              docId: 'helloworld3'
              create: true
              contents: { "message":"Hello World", "id": 3 }
          }

         U1db.Index{
             database: aDatabase
             id: by_helloworld
             expression: ["id","message"]
         }

         U1db.Query{
             id: aQuery
             index: by_helloworld
         }

  
  I get this output:

  (0) 'undefined 1'
  (1) 'undefined 2'
  (2) 'undefined 3'

  JSON.stringify(aQuery) shows that this is not a bug related to ListView, but that the Documents don’t show up properly:
  {"index":{"database":{"error":"","objectName":"","path":"aDatabase5"},"name":"","objectName":"","expression":{"0":"id","1":"message"}},"objectName":"","results":[{"id":1},{"id":2},{"id":3}],"documents":{"0":"helloworld1","1":"helloworld2","2":"helloworld3"}}

  
  Making "message" an Integer or "id" a String doesn’t change anything: "message" is undefined while "id" works. Swapping "message" and "id" in contents ({ "id": 3, "message":"Hello World" } instead of { "message": "Hello World", "id":3 }) doesn’t change anything, either.



  But now, things are getting very strange, if i don’t call "message"
  "message" anymore, but "dj", like this:

  import QtQuick 2.0
  import U1db 1.0 as U1db
  import Ubuntu.Components 0.1

  MainView {
      width: units.gu(45)
      height: units.gu(80)

          U1db.Database {
              id: aDatabase
              path: "aDatabase5"
          }

         U1db.Document {
              database: aDatabase
              docId: 'helloworld1'
              create: true
              defaults: {  "id": 1 ,"dj":"Hello World",}

          }

         U1db.Document {
              database: aDatabase
              docId: 'helloworld2'
              create: true
              defaults: {  "id": 2 , "dj":"Hello World",}
          }

         U1db.Document {
              database: aDatabase
              docId: 'helloworld3'
              create: true
              contents: {  "id": 3, "dj":"Hello World", }
          }

         U1db.Index{
             database: aDatabase
             id: by_helloworld
             expression: ["id","dj"]
         }

         U1db.Query{
             id: aQuery
             index: by_helloworld
         }

          Tabs {
              id: tabs

              Component.onCompleted: console.log(JSON.stringify(aQuery))

              Tab {
                  title: i18n.tr("Hello U1Db!")

                  page: Page {
                      id: helloPage

                      ListView {
                          width: units.gu(45)
                          height: units.gu(80)
                          model: aQuery
                          delegate: Text {
                              text: "(" + index + ") '" + contents.dj + " " + contents.id + "'"
                      }
                  }
              }
          }
      }
  }

  
  In that case, all of a sudden, you can see "dj", while "id" is undefined:

  (0) 'Hello World undefined'
  (1) 'Hello World undefined'
  (2) 'Hello World undefined'

  
  JSON.stringify(aQuery) gives accordingly:
   {"index":{"database":{"error":"","objectName":"","path":"aDatabase5"},"name":"","objectName":"","expression":{"0":"id","1":"dj"}},"objectName":"","results":[{"dj":"Hello World"},{"dj":"Hello World"},{"dj":"Hello World"}],"documents":{"0":"helloworld1","1":"helloworld2","2":"helloworld3"}}

  
  As above, changing the type of the variables or swapping their order doesn’t change a thing.

To manage notifications about this bug go to:
https://bugs.launchpad.net/u1db-qt/+bug/1215898/+subscriptions