View Full Version : [OPEN] Sencha Touch 2.1 marks Ajax JSON response as failed if server returns empty array

19 Nov 2012, 5:05 AM
In Ext.data.reader.Reader nullResultSet is defined like this:

// Empty ResultSet to return when response is falsy (null|undefined|empty string)
nullResultSet: new Ext.data.ResultSet({
total : 0,
count : 0,
records: [],
success: false

The problem is that the Ext.data.reader.Reader#readRecords has the following code:

if (isArray && !data.length) {
return me.nullResultSet;

that causes nullResultSet to be returned not only in cases specified above, but also for empty arrays. Because nullResultSet has success flag set to false, it causes the whole response to be incorrectly marked as failed.

BTW. I can fix it myself, but currently there's no way to contribute to Sencha Touch, right? Any plans to use GitHub or something similar for hosting Sencha Touch code?

Here's how I fixed it (touch/src/data/reader/Reader.js)

if (isArray && !data.length) {
- return me.nullResultSet;
+ return new Ext.data.ResultSet({
+ total : 0,
+ count : 0,
+ records: [],
+ success: true
+ });

19 Nov 2012, 12:50 PM
Thanks for the report! I have opened a bug in our bug tracker.

17 Dec 2012, 11:59 AM
I've just noticed that this ticket is closed, but not fixed, and it says "Looks like we can't reproduce the issue or there's a problem in the test case provided". What does it mean exactly? Do you want me to provide some more info or a test case?

23 Dec 2012, 11:45 AM
To make it easier for you guys to reproduce this issue, here's a screencast: http://www.screencast.com/users/szimek/folders/Jing/media/3759e51d-943e-489a-93a0-1fc79e11833d

The first call to Ext.getStore("Resources").load() fetches 2 records and properly displays them in the list view. The second call fetches an empty array (valid JSON) and throws exception event instead of displaying empty list. If you want I can upload code to GitHub, but it's just a single list view + model with name field and store with REST proxy and JSON reader.

Hope that helps reproducing this issue.


2 Jan 2013, 4:17 AM
Bump. I really do hope you'll reopen this issue after watching the screencast.

26 Feb 2013, 4:04 AM
Bump. Reposting link to screencast: http://www.screencast.com/users/szimek/folders/Jing/media/3759e51d-943e-489a-93a0-1fc79e11833d

26 Feb 2013, 6:01 AM
I have seen the same thing in my app. I worked around it by calling removeAll instead of setData when I get an empty array. If this is not a bug, it is annoying that they have decided to change the way empty arrays are handled. All of my web services and code were setup on the assumption that an empty array was okay.

27 Feb 2013, 6:15 AM
It got fixed by returning empty ResultSet, with 0 members, BUT, status is set to false, so if you have some items in your store, and server response returns [], old entries from your store are not deleted from your store, event if they are not existing on server :-(

27 Feb 2013, 6:23 AM
I fixed it by creating an `emptyResultSet` that is almost exactly the same as `nullResultSet` but has success flag set to true (a slightly more clean approach than in my first post).

But it would be nice if someone from Sencha confirmed if it's a desired behavior (and if yes, then why) or a bug.

27 Feb 2013, 7:08 AM
I changed server API so it returns not only raw data but also 'success' property, that also solves the problem.

12 Mar 2013, 7:18 AM
We hit upon the same problem. Should be fixed in an upcoming version of Sencha Touch

16 Apr 2013, 11:15 PM
I haven't updated my app yet, but looking at the source code it looks like this issue hasn't been fixed in 2.2.0.

It's closed, so unless somebody reopens it again it will never get fixed.

26 Jun 2013, 2:09 AM
This bug also affects stores using memory proxies. Then you can just do:

and immediately see it ignored, and the previous value retained. I'm still seeing this in sencha 2.2.1. I fixed it with an override of Ext.data.reader.Reader, but that's a pain to maintain.

It's obvious that no data is a valid, non-error condition, and shouldn't be treated as an error.

3 Jul 2013, 12:10 PM
I'd like to second this bug. It's not just with Ajax proxies; it affects all proxies. Here's an example:

Ext.define('User', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'phone', type: 'string', mapping: 'phoneNumber'}

var store = Ext.create('Ext.data.Store', {
model: 'User',
data : [],
proxy: {
type: 'memory',
reader: {
type: 'json'

callback: function(records, operation, success) {
console.log(success); // logs "false"