Deleting an event from scheduler sometimes results in error

Using backbone with scheduler. Depending on the conditions, we remove an event from the collection with events.remove(events.get(IdOfEventToRemove));. Sometimes this works, sometimes it fails. The area it fails at is scheduler.isOneDayEvent in dhtmlxscheduler_recurring.js:296. that function is called at some point from within the scheduler with an undefined variable. But then I step through the stack trace, it looks as if it has the event all the way until scheduler.deleteEvent:3356. At that point, the scheduler delete’s the event, but in the following two lines, this.unselect(id) and this.event_updated(ev); it is referencing the event it just deleted. As it continues through the scheduler, it gets to isOneDayEvent and checks the rec_type of an undefined variable, hence the error.

The biggest pain is that it happens only sometimes, and although I can reproduce the error, it doesn’t seem very consistent.

This is where I call my Backbone collection to remove an event

events.remove(events.get(eventID));

Here is the stacktrace when the delete succeeds (breakpoint at isOneDayEvent)

scheduler.isOneDayEvent (dhtmlxscheduler_recurring.js:296) scheduler._recalculate_timed (dhtmlxscheduler.js:3543) scheduler.render_view_data (dhtmlxscheduler.js:3465) scheduler.event_updated (dhtmlxscheduler.js:3416) scheduler.deleteEvent (dhtmlxscheduler.js:3358) (anonymous function) (dhtmlxscheduler_mvc.js?!:6) Backbone.Events.trigger (backbone.js:163) _.extend._onModelEvent (backbone.js:844) Backbone.Events.trigger (backbone.js:170) _.extend.remove (backbone.js:652) (anonymous function) (timeline.js:1525)

And here is where it breaks

scheduler.isOneDayEvent (dhtmlxscheduler_recurring.js:296) scheduler.updateEvent (dhtmlxscheduler_all_timed.js:8) scheduler.unselect (dhtmlxscheduler.js:2052) scheduler.deleteEvent (dhtmlxscheduler.js:3357) (anonymous function) (dhtmlxscheduler_mvc.js?!:6) Backbone.Events.trigger (backbone.js:163) _.extend._onModelEvent (backbone.js:844) Backbone.Events.trigger (backbone.js:170) _.extend.remove (backbone.js:652) (anonymous function) (timeline.js:1525)

Hi,
please try the most recent dev version of the component (we plan to release the update in a nearest days). Is the problem fixed there?
dhtmlxScheduler_140529.zip (520 KB)

Unfortunately, I am unable to update the entire scheduler, since I’ve made changes to another file to allow me to remove markedTimespans with just the timelines ID.

I did throw in an type check in that method to return true if undefined, as the only case where it shows up is when working with a single event.
Once we package up our release, I’ll be able to integrate and test out the latest stable version.

    scheduler.isOneDayEvent = function (b) {
        if(typeof b === "undefined")
            return !0;
        return b.rec_type ? !0 : a.call(this, b);
    };

I’ll be sure to post more once I am able to test the latest release.

If you’ve made changes only in extension files (dhtmlxscheduler_limit.js and dhtmlxscheduler_timeline.js), you may try to use newest dhtmlxscheduler.js with your customized extensions. Probably they will work that way.

Additionally, if your changes are limited to several methods, you can put the customized declaration in a custom js file and load it on top of original dhtmlxScheduler files. So they overwrite original methods, leaving you posibility to update the original code files. I mean, for example, if you need to change behavior of scheduler.addEvent method(which is defined in dhtmlxscheduler.js), you create file named somehow like dhtmlxscheduler_custom.js and with code like following:scheduler.addEvent = function(...){ //copy of original method with the required changes applied };
And add it to the page in following order:
dhtmlxscheduler.js
dhtmlxscheduler_custom.js

That way your application will have the customized method, which most probably will still work if you replace dhtmlxscheduler.js with the different version. Or at least the process of updating will be much less painfull.
Keeping modifications separately from the original sources is a usual way of modifying behaviors of the calendar in applications

I have updated the code, but now I am getting error ‘set’ of undefined in the dhtmlxscheduler_mvc.
It seems that d.get(ID) ((Collection).get()) doesn’t return anything.

Uncaught TypeError: Cannot read property 'set' of undefined 
dhtmlxscheduler_mvc.js?!:63
(anonymous function) dhtmlxscheduler_mvc.js?!:63
z dhtmlxscheduler.js:264
obj.callEvent dhtmlxscheduler.js:258