Bundled object in obj_delete is None?

164 views
Skip to first unread message

Stodge

unread,
Jul 17, 2015, 9:19:25 AM7/17/15
to django-...@googlegroups.com
I'm trying to override obj_delete but the object in the bundle is None:

def obj_delete(self, **kwargs):

    bundle
= kwargs['bundle']
   
print("Object: %s" % (bundle.obj))
   
print("User: %s" % (bundle.request.user))


So the output is:

Object: None
User: (valid user info)

Am I doing something silly? The delete works perfectly by the way.

Thanks


Message has been deleted

Mike Stoddart

unread,
Jul 17, 2015, 9:38:04 AM7/17/15
to django-...@googlegroups.com
Ok cool thanks. I'll try that. Instead I retrieved 'pk' from kwargs and manually loaded the object. It just seems odd that bundle.obj is None. Maybe I need to invoke obj_delete from the parent class before I do my own checks?

On Fri, Jul 17, 2015 at 9:32 AM, Thibault Appourchaux <thibault.a...@gmail.com> wrote:
Hi Stodge,

I had the same issue and I ended up using obj_get to get my object.

Like this:
def obj_delete(self, **kwargs):
   bundle
= kwargs['bundle']

   
try:
       bundle
.obj = self.obj_get(bundle=bundle, **kwargs)

       
print("Object: %s" % (bundle.obj))
       
print("User: %s" % (bundle.request.user))


   
except ObjectDoesNotExist:
       
raise NotFound("A model instance matching the provided arguments could not be found.")
   

--
You received this message because you are subscribed to a topic in the Google Groups "Tastypie" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-tastypie/PsygVX9MIos/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-tastyp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Mike Stoddart

unread,
Jul 17, 2015, 9:52:27 AM7/17/15
to django-...@googlegroups.com
Ok, thanks Thibault.

On Fri, Jul 17, 2015 at 9:51 AM, Thibault Appourchaux <thibault.a...@gmail.com> wrote:
As you can see here https://github.com/django-tastypie/django-tastypie/blob/master/tastypie/resources.py#L1474obj_delete seems to be a special case where Bundle is being manually built with only request provided.
obj_get seems to be performed later, in obj_deletehttps://github.com/django-tastypie/django-tastypie/blob/master/tastypie/resources.py#L2207 )

The problem is that if you invoke the parent obj_delete as you suggest, your object will not exist anymore :/
Reply all
Reply to author
Forward
0 new messages