Strange behaviour with multiple elements on first level in contents

Bug #1215898 reported by Joshua Gleitze
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
U1DB Qt/ QML
Fix Committed
High
Cris Dywan
u1db-qt (Ubuntu)
Fix Released
Undecided
Unassigned

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.

Related branches

Revision history for this message
Joshua Gleitze (joshua-gleitze) wrote :

All of the above works as expected if you have one element on the first level an the other elements are children of the one element.

Cris Dywan (kalikiana)
Changed in u1db-qt:
status: New → Confirmed
importance: Undecided → High
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

Fix committed into lp:u1db-qt at revision 114, scheduled for release in u1db-qt, milestone 1.0

Changed in u1db-qt:
status: Confirmed → Fix Committed
Changed in u1db-qt:
milestone: none → 1.0
assignee: nobody → Christian Dywan (kalikiana)
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package u1db-qt - 0.1.5+14.04.20140313-0ubuntu1

---------------
u1db-qt (0.1.5+14.04.20140313-0ubuntu1) trusty; urgency=low

  [ CI bot ]
  * No change rebuild against Qt 5.2.1.

  [ Christian Dywan ]
  * Adopt xvfb.sh script from ui toolkit to run tests
  * Sort out build warnings and make them always fatal.
  * Implement Database.removeDoc method and use it in unit test
    Functionally this is equivalent to replacing the doc with an empty
    one. (LP: #1243395)
  * Use new-style qmlrunner log option to enable stdout.
  * Query improvements and more advanced example. (LP: #1271977,
    #1271972, #1266478)
  * Store whole document contents in the results and unit test that.
    (LP: #1271973)
  * Reverse query logic to check non-matching and internally convert
    between query syntaxes. (LP: #1284194, #1214538, #1215898)
  * Revert r113 and update unit test to verify previous behavior
 -- Ubuntu daily release <email address hidden> Thu, 13 Mar 2014 23:12:40 +0000

Changed in u1db-qt (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.