Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related fields (ForeignKey) models get saved for no reason. [Performance Issue] #397

Closed
JanezStupar opened this issue Mar 5, 2012 · 9 comments · May be fixed by #594
Closed

Related fields (ForeignKey) models get saved for no reason. [Performance Issue] #397

JanezStupar opened this issue Mar 5, 2012 · 9 comments · May be fixed by #594
Milestone

Comments

@JanezStupar
Copy link

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.

The issue manifests itself in save_related model of ModelResource. 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: toastdriven@600a033

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

@ericholscher
Copy link

I believe I am seeing this as well. It's a pretty basic structure, so https://gist.github.com/f3db0df350d0a4a7f5f2 causes the project to be saved.

@miki725
Copy link

miki725 commented Mar 19, 2012

Not sure if this applies to this issue however I have to following problem:

I have a resource (MainFooResource) with a foreign key to another resource (ForeignFooResource). In the ForeignFooResource resource I have a character field to which I apply hydration and dehydration cycles. So the value in the db is different from what the api consumer sees.

Now whenever I send a non-GET request to the MainFooResource resource, the ForeignFooResource resource is saved, however the hydration cycle is not applied to it. So what happens is that the dehydrated value for the character field gets saved into the db.

Is this my fault or something in tastypie not working right?

@philipn
Copy link
Contributor

philipn commented Aug 2, 2012

I took some of @joshbohde's work and massaged it into a fix here: https://github.com/toastdriven/django-tastypie/pull/594

@gstf
Copy link

gstf commented Aug 6, 2012

+1

3 similar comments
@graphiclife
Copy link

+1

@mattdennewitz
Copy link

+1

@ondrowan
Copy link
Contributor

+1

@silviomoreto
Copy link

+1

@kvnn
Copy link

kvnn commented Apr 15, 2013

++

numan pushed a commit to numan/django-tastypie that referenced this issue Jul 21, 2013
…, django-tastypie#594 and others.

Extra tests assuring through model metadata is saved; fixing backwards/forwards incompatability with MockRequest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants