mreichelt
mreichelt

Reputation: 12455

App Engine: different results for same objectify query

I am developing a small backend with app engine. Now I get some weird behaviour after saving an entity multiple times with different values. My code to load entities is the same for all entities - each entity gets a changeId so I can transfer only changed entities to the clients:

public class VersionableRecordHelper<T extends VersionableRecord> {

final Class<T> clazz;

public VersionableRecordHelper(Class<T> clazz) {
    this.clazz = clazz;
}

Query<T> load() {
    return ofy().load().type(clazz);
}

List<T> loadOrdered() {
    return load().order("changeId").list();
}

public List<T> loadOrdered(Long since) {
    return since == null ? loadOrdered() : load().filter("changeId >", since).order("changeId").list();
}

}

The clients then can query all objects of a class by providing a since value. For example:

private final VersionableRecordHelper<Cat> helper
    = new VersionableRecordHelper<>(Cat.class);

// actually an @ApiMethod, simplified here
public List<Cat> getCats(Long since) {
    return helper.loadOrdered(since);
}

My Cat entity looks like the following:

@Entity
@Cache
@JsonSerialize(include = JsonSerialize.Inclusion.ALWAYS)
public class Cat extends VersionableRecord {
    // some fields, getters, setters
}

public class VersionableRecord {
    @Id
    private String id;

    @Index
    private Long changeId;

    // getters, setters and more
}

Now, if I do the same REST request with since == 4, I get completely different results - sometimes with changeId == 5, but also with 2, 3 or 4 - which should not even be possible!

I am completely lost here. This is what I checked yet:

Does anyone have a helpful idea? I also checked for different type of entities - the same behaviour.

Upvotes: 1

Views: 237

Answers (1)

stickfigure
stickfigure

Reputation: 13556

Wild guess, this is related to FAQ #3:

https://code.google.com/p/objectify-appengine/wiki/FrequentlyAskedQuestions#Strange_things_are_showing_up_in_my_session_cache!_(or_missing_f

or, when googlecode dies, the third one down:

https://github.com/objectify/objectify/wiki/FrequentlyAskedQuestions

You need to have the ObjectifyFilter installed otherwise you will bleed session data into subsequent requests. Upgrade to a more recent version of Objectify; it will give you a more explicit error (at the cost of complicating test and remote api usage, but that's a different story).

If this isn't your issue, you need to describe your exact code in more detail.

Upvotes: 2

Related Questions