Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite: Model.find returns wrong cached entry #350

Closed
Locke opened this issue Oct 4, 2013 · 2 comments
Closed

sqlite: Model.find returns wrong cached entry #350

Locke opened this issue Oct 4, 2013 · 2 comments

Comments

@Locke
Copy link

Locke commented Oct 4, 2013

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.

@Locke
Copy link
Author

Locke commented Oct 6, 2013

I just read in an other issue:

What the cache option does is to check if a row of a table was already converted [...]
This means we always do the query and see what IDs are returned

Using .only(["id", "log"]) works fine.

@dresende
Copy link
Owner

dresende commented Nov 9, 2013

Sorry for the delay. Be aware that:

  • .only is not well structured, it should at least fetch the primary properties...
  • node-sqlite3 > 2.1.7 does not pass orm tests. I have an open ticket but they don't seem to solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants