Skip to content

sqlite: Model.find returns wrong cached entry #350

Description

@Locke

Today I upgraded from v2.1.0 to v2.1.2 and noticed that Model.find() returned cached entries from a previous fetch that had different conditions. I also tried the current master version.

I am using sqlite3 3.7.15.2-1ubuntu1 with node-sqlite v2.1.17.

git bisect gave me that 9141d43 is the faulting commit.

Test case:

var orm = require("orm");

var Logs;

orm.connect("sqlite:///tmp/orm_cache.sqlite?debug=true", function (err, db) {
    Logs = db.define(
        "log", {
            "date": Date,
            "log": String
        });

    db.sync(function() {
        Logs.create([
            {date: new Date(), log: "test1"},
            {date: new Date(), log: "test2"},
        ], function(err, data) {
            getLog(1, "getLog 1 after insert");
        });
    }); 
});


function getLog(id, output) {
    //Logs.find({id: id},{cache: false}).only(["log"]).run(function(err, data){
    //Logs.find({id: id}).run(function(err, data){
    Logs.find({id: id}).only(["log"]).run(function(err, data){
        console.log(output + ": " + data[0].log);
    });
};

setTimeout(function() {getLog(2, "getLog 2 after 1 second");}, 1000);

expected output:

getLog 1 after insert: test1
getLog 2 after 1 second: test2

actual output:

getLog 1 after insert: test1
getLog 2 after 1 second: test1

With {cache: false} or without only I get the expected output.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions