error: 'TypeError: <functools.partial object at 0x7f99df670998> is not a Python function'

17 views
Skip to first unread message

Chunlin Zhang

unread,
Feb 3, 2016, 9:44:34 PM2/3/16
to uli...@googlegroups.com
看了相关的文件 plugs/plugs/rbac_man/views.py 里:

    def add(self):
        """
        Add new role
        """
        
        from uliweb.utils.generic import AddView
        from functools import partial
        
        url = partial(url_for, RoleView.view)
        
        default_data = {'reverse':False}
        
        fields = [
            {'name':'name', 'verbose_name':_('Name')},
            {'name':'description', 'verbose_name':_('Description')},
        ]

        view = AddView(self.model, url, default_data=default_data, fields=fields)
        return view.run()

这里直接出问题的 functools.partial object 是在上面这段代码生成的, 我还看不太懂是咋回事,traceback在后面 

----
traceback:

Traceback (most recent call last):
  File "/home/zhangclb/oss/uliweb/uliweb/contrib/staticfiles/wsgi_staticfiles.py", line 91, in __call__
    return self.app(environ, start_response)
  File "/home/zhangclb/oss/uliweb/uliweb/core/SimpleFrame.py", line 1482, in __call__
    response = self._open(environ)
  File "/home/zhangclb/oss/uliweb/uliweb/core/SimpleFrame.py", line 1427, in _open
    response = self.call_view(mod, handler_cls, handler, req, res, kwargs=values)
  File "/home/zhangclb/oss/uliweb/uliweb/core/SimpleFrame.py", line 970, in call_view
    result = self.call_handler(handler, request, response, env, wrap, args, kwargs)
  File "/home/zhangclb/oss/uliweb/uliweb/core/SimpleFrame.py", line 1081, in call_handler
    result = self._call_function(handler, request, response, env, args, kwargs)
  File "/home/zhangclb/oss/uliweb/uliweb/core/SimpleFrame.py", line 1074, in _call_function
    result = handler(*args, **kwargs)
  File "/home/zhangclb/oss/plugs/plugs/rbac_man/views.py", line 80, in add
    return view.run()
  File "/home/zhangclb/oss/uliweb/uliweb/utils/generic.py", line 1029, in run
    return self.execute(json_result)
  File "/home/zhangclb/oss/uliweb/uliweb/utils/generic.py", line 977, in execute
    return self.on_success(d, json_result)
  File "/home/zhangclb/oss/uliweb/uliweb/utils/generic.py", line 939, in on_success
    return redirect(self.get_url(obj))
  File "/home/zhangclb/oss/uliweb/uliweb/utils/generic.py", line 902, in get_url
    args = inspect.getargspec(self.ok_url).args
  File "/usr/lib/python2.7/inspect.py", line 816, in getargspec
    raise TypeError('{!r} is not a Python function'.format(func))
TypeError: <functools.partial object at 0x7f99df670998> is not a Python function

Chunlin Zhang

unread,
Apr 1, 2016, 3:59:09 AM4/1/16
to uli...@googlegroups.com
今天又发生了这个问题,因为我发现我把当时临时改的去掉了,所以又出现了
这样改就会正常:
diff --git a/uliweb/utils/generic.py b/uliweb/utils/generic.py
index e453b18..87f0edf 100644
--- a/uliweb/utils/generic.py
+++ b/uliweb/utils/generic.py
@@ -913,8 +913,9 @@ class AddView(object):
             return errors
 
     def get_url(self, obj):
+        from functools import partial^M
         #guess ok_url kwargs, it could be (id) or (obj)
-        if callable(self.ok_url):
+        if callable(self.ok_url) and type(self.ok_url)!=partial:^M
             args = inspect.getargspec(self.ok_url).args
             kwargs = {}
             _dict = obj.to_dict()

limodou

unread,
Apr 4, 2016, 5:48:54 AM4/4/16
to uliweb
ok_url可以是一个函数,建议定义为函数来处理,如:

def get_url(id):
return url_for(RoleView.view, id=id)
> --
> -- ----
> Project : https://github.com/limodou/uliweb
> doc : http://limodou.github.com/uliweb-doc
> ---
> You received this message because you are subscribed to the Google Groups
> "Uliweb" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to uliweb+un...@googlegroups.com.
> To post to this group, send email to uli...@googlegroups.com.
> Visit this group at https://groups.google.com/group/uliweb.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/uliweb/CAG2rzAkd57TnUF8c3wwNM7YikBwJiNFYu9Typ-R%3DNRar-5b9Hw%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: https://github.com/limodou/uliweb
My Blog: http://my.oschina.net/limodou

Chunlin Zhang

unread,
Apr 4, 2016, 9:05:23 PM4/4/16
to uli...@googlegroups.com
我是说你现在的代码有问题,需要修复
现在的代码在rbac_man里会出问题,貌似你原来的代码能工作,但是后来改坏了
目前的代码在 args = inspect.getargspec(self.ok_url).args 这里, 如果 self.ok_url 是 particial的时候会出错
我给你提个PR看看吧

Chunlin Zhang

unread,
May 9, 2016, 2:30:43 AM5/9/16
to uli...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages