toastdriven/django-tastypie — Issue #397: Related fields (ForeignKey) models get saved for no reason. [Performance Issue]
Author: JanezStupar
Created: 2012-03-05 10:17:47+00:00
State: open

While searching around I noticed something that got me feeling pretty uneasy.

What I noticed is that Tastypie goes and not only loads (which it needs for purpose of building reverse URI's) but also SAVES related models. Related in a sense of foreign key, where related models are merely being pointed to.

Consider the example provided below:
http://pastebin.com/F27w5Q6N

We have a parent model (EventResource), which has a child (CustomerResource) and two references (SiteResource,CustomerResourceResource). The child is provided inline and is expected to get updated/created. However Site and CustomerResource are not. For instance Site is the root model and that could cause congestion problems on a site with elevated loads and is bad for performance reasons, obviously.

To repeat the phenomena, set a breakpoint in the line 34 of this paste (http://pastebin.com/6FLwVLDk). Then step through and watch how related models get saved.

The code is from commit: https://github.com/toastdriven/django-tastypie/commit/600a033ba310c8966b6c3c4df4cb9977837273d2

I believe that this issue may be linked to:
https://github.com/toastdriven/django-tastypie/issues/371

and may be linked to:
https://github.com/toastdriven/django-tastypie/issues/390