Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tastypie NotFound: Invalid resource lookup data provided (mismatched type)

Right I am having a hard time understanding this one,

On my local environment I have integrated username lookup for the django User object:

class UserResource(ModelResource):
    class Meta:
        queryset = User.objects.all()
        excludes = ['password', 'email', 'is_staff', 'is_active', 'is_superuser']
        resource_name = 'users'
        include_resource_uri = False
        filtering = {
            'username': ALL
        }

    def prepend_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/(?P<username>[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
        ]

In tastypie's source, resources.py I have added two print statements at line 1800+

def obj_get(self, request=None, **kwargs):
    """
    A ORM-specific implementation of ``obj_get``.

    Takes optional ``kwargs``, which are used to narrow the query to find
    the instance.
    """
    try:
        print "1, ", kwargs
        base_object_list = self.get_object_list(request).filter(**kwargs)
        print "2, ", base_object_list
        # etcetera

Visiting:

/api/v1/users/foo/?format=json

this prints:

1,  {'username': foo'}
2,  [<User: foo>]
1,  {'id': 1}
2,  [<User: foo>]

And returns the correct JSON object.

However, on my remote (dev) server I have the exact same setup (I double checked all files), the only difference seems to be it's running the tastypie python 2.7 egg instead of 2.6, anyway I get this print:

1,  {'pk': u'foo'}
[27/Jul/2012 10:48:37] "GET /api/v1/users/foo/?format=json HTTP/1.0" 404 1219

I also get this stacktrace:

{
error_message: "Invalid resource lookup data provided (mismatched type).",
traceback: "Traceback (most recent call last):

  File "...path.../resources.py", line 192, in wrapper
    response = callback(request, *args, **kwargs)

  File "...path.../resources.py", line 406, in dispatch_detail
    return self.dispatch('detail', request, **kwargs)

  File "...path.../resources.py", line 427, in dispatch
    response = method(request, **kwargs)

  File "...path.../resources.py", line 1051, in get_detail
    obj = self.cached_obj_get(request=request, **self.remove_api_resource_names(kwargs))

  File "...path.../resources.py", line 921, in cached_obj_get
    bundle = self.obj_get(request=request, **kwargs)

  File "/...path.../resources.py", line 1765, in obj_get
    raise NotFound("Invalid resource lookup data provided (mismatched type).")

NotFound: Invalid resource lookup data provided (mismatched type).
"

}

Any thoughts?

like image 294
Hedde van der Heide Avatar asked Dec 16 '22 21:12

Hedde van der Heide


1 Answers

Right, the answer:

changing prepend_urls to (to be deprecated) override_urls fixes the bug, I will report this one at github, seems to be a 2.7 egg issue

like image 129
Hedde van der Heide Avatar answered Dec 22 '22 01:12

Hedde van der Heide