From 8c0916a7bdb638bef61bea0bdf16c25ba1dbf1e4 Mon Sep 17 00:00:00 2001 From: Oleg Vdovenko Date: Tue, 23 Jan 2024 21:45:21 +0200 Subject: [PATCH 1/2] [FIX] wrong context passed in collection.create --- backbone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backbone.js b/backbone.js index c364267a1..4fdad1968 100644 --- a/backbone.js +++ b/backbone.js @@ -1085,7 +1085,7 @@ var success = options.success; options.success = function(m, resp, callbackOpts) { if (wait) { - m.off('error', this._forwardPristineError, this); + m.off('error', collection._forwardPristineError, collection); collection.add(m, callbackOpts); } if (success) success.call(callbackOpts.context, m, resp, callbackOpts); From d981caa7bc7ab93fb97f780db5b6ddf88dee5f9e Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Tue, 23 Jan 2024 21:28:05 +0100 Subject: [PATCH 2/2] Add regression test for #4284 --- test/collection.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/collection.js b/test/collection.js index adf16dfe9..4ceeaa6ac 100644 --- a/test/collection.js +++ b/test/collection.js @@ -674,6 +674,16 @@ this.ajaxSettings.success(); }); + QUnit.test('successful create with wait:true drops special error listener (#4284)', function(assert) { + assert.expect(1); + var collection = new Backbone.Collection; + collection.url = '/test'; + collection.on('error', function() { assert.ok(true); }); + var model = collection.create({id: '1'}, {wait: true}); + this.ajaxSettings.success(); + model.trigger('error'); + }); + QUnit.test('failing create pre-existing with wait:true triggers once (#4262)', function(assert) { assert.expect(1); var model = new Backbone.Model;