Tuesday, June 3, 2014

Re: Reference to form cleaned data field throws TypeError: 'exceptions.AttributeError' object is not callable

clean_email needs to return the cleaned email regardless of whatever else it does.  This clean_email returns email when it's valid but not when it isn't.  This means that whatever Django internals are expecting, and trying to operate upon, its return value are throwing exceptions instead.  This is also why the behavior is intermittent - you only see it with invalid emails. --ay


On Tue, Jun 3, 2014 at 8:24 PM, Gloria W <gloriajw66@gmail.com> wrote:
This is the strangest bug I've seen in Django. (1.6.4 on Ubuntu 14.04, Python 2.7.6)
 It is sporadic, but once it starts happening, it is consistent until I restart the process.
To try and debug it, I print the value of self.cleaned_data just before it occurs. The value prints fine.


The code:

    def clean_email(self):
        logger.warn("Debugging Attribute error:%s" % pprint.pformat(self.cleaned_data))
        try:
            FytUser.objects.get(email=self.cleaned_data['email'])
            raise forms.ValidationError('A user with that email address already exists.')
        except FytUser.DoesNotExist:
            return self.cleaned_data['email']


The traceback in the uwsgi logs:

Debugging Attribute error:{'email': u'test@test.net'}

Traceback (most recent call last):      File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 114, in get_response      response = wrapped_callback(request, *callback_args, **callback_kwargs)      File "./registration/views.py", line 54, in preregister_check      if form.is_valid():      File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 129, in is_valid      return self.is_bound and not bool(self.errors)      File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 121, in errors      self.full_clean()      File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 273, in full_clean      self._clean_fields()      File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 291, in _clean_fields      value = getattr(self, 'clean_%s' % name)()      File "./fyt/forms.py", line 87, in clean_email      FytUser.objects.get(email=self.cleaned_data['email'])      File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 151, in get      return self.get_queryset().get(*args, **kwargs)      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 307, in get      self.model._meta.object_name)    TypeError: 'exceptions.AttributeError' object is not callable      <WSGIRequest  path:/prereg_check/,  GET:<QueryDict: {}>,  POST:<QueryDict: {u'birthday_year': [u'1900'], u'password2': [u'xxxxx'], u'last_name': [u'W'], u'is_member': [u'1'], u'gender': [u'2'], u'first_name': [u'G'], u'birthday_day': [u'01'], u'birthday_month': [u'01'], u'csrfmiddlewaretoken': [u'MYKnPppKtnKV4ybQ86rkYsv8Er2LIc1a'], u'password': [u'xxxxx'], u'email': [u'test@test.net'], u'discount_code': [u'']}>,  COOKIES:{'_ga': 'xxxxxxx',   'csrftoken': 'xxxxxxxxx',   'sessionid': 'xxxxxx',   'signup_modal': 'true'},  META:{'CONTENT_LENGTH': '221',   'CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',   u'CSRF_COOKIE': u'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',   'DOCUMENT_ROOT': '/home/xxxxxx',   'HTTP_ACCEPT': 'application/json, text/javascript, */*; q=0.01',   'HTTP_ACCEPT_ENCODING': 'gzip, deflate',   'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.5',   'HTTP_CACHE_CONTROL': 'no-cache',   'HTTP_CONNECTION': 'keep-alive',   'HTTP_CONTENT_LENGTH': '221',   'HTTP_CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',   'HTTP_COOKIE': 'csrftoken=xxxxxxxxxxx; sessionid=xx; _ga=xxxxxx; signup_modal=true',   'HTTP_HOST': 'findyourtrainer.com',   'HTTP_PRAGMA': 'no-cache',   'HTTP_REFERER': 'https://xxxxx/register?next=/',   'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0',   'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',   'PATH_INFO': u'/prereg_check/',   'QUERY_STRING': '',   'REMOTE_ADDR': 'xxxxxxxxxxxxxxxx',   'REMOTE_PORT': '37998',   'REQUEST_METHOD': 'POST',   'REQUEST_URI': '/prereg_check/',   u'SCRIPT_NAME': u'',   'SERVER_NAME': 'xxxx.com',   'SERVER_PORT': '443',   'SERVER_PROTOCOL': 'HTTP/1.1',   'UWSGI_SCHEME': 'https',   'uwsgi.node': 'xxxxxxxxxxxx.com',   'uwsgi.version': '2.0.4',   'wsgi.errors': <open file 'wsgi_errors', mode 'w' at 0x7f720e9dc150>,   'wsgi.file_wrapper': <built-in function uwsgi_sendfile>,   'wsgi.input': <uwsgi._Input object at 0x7f72072c3a50>,   'wsgi.multiprocess': True,   'wsgi.multithread': False,   'wsgi.run_once': False,   'wsgi.url_scheme': 'https',   'wsgi.version': (1, 0)}>    
This looks like a memory leak to me. Has anyone else seen this?
Thanks in advance,
~G~

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/11ddf2f6-7a07-4c1e-86db-b7e0223546ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Andromeda Yelton
Board of Directors, Library & Information Technology Association: http://www.lita.org
Advisor, Ada Initiative: http://adainitiative.org

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFE1XCbywTwW%2BS8_0d6eoJWVYPn_KnXNcZv8eWkc5f%3D-MqqiMA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment