Opened 3 years ago

Closed 2 years ago

#19417 closed Bug (duplicate)

Django 1.4.2 does not support Jython 2.5.3 (strptime issue)

Reported by: fvox13 Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords: strptime jython forms datetimefield
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by aaugustin)

As near as I can tell, this is a problem with Django / Jython compatibility and not my code... if I'm wrong feel free to slap my wrist...

A form was created with the following field:
start_date = forms.DateTimeField(required=True, widget=forms.DateTimeInput({'class': 'datetime'}))

The following POST data was passed:
start_date u'11/03/2012 00:00:00'

The following traceback was received when I check for form.is_valid() in the view:

Environment:

Request Method: POST
Request URL: http://127.0.0.1:6701/reports/ondemand/Top_Incident_Types/

Django Version: 1.4.2
Python Version: 2.5.3
Installed Applications:
('django.contrib.formtools',
 'django.contrib.humanize',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'mykui.accounts',
 'mykui.console',
 'mykui.mykonfig',
 'mykui.reports',
 'mykui.status',
 'mykui.updates',
 'mykui.util')
Installed Middleware:
('django.middleware.gzip.GZipMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'mykui.middleware.UserMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'mykui.middleware.UnavailableMiddleware',
 'mykui.middleware.SystemMessageMiddleware',
 'mykui.middleware.TimezoneMiddleware')


Traceback:
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/views/decorators/http.py" in inner
  41.             return func(request, *args, **kwargs)
File "/usr/share/msa/ui/mykui/decorators.py" in _inner
  49. 		return view(*args, **kwargs)
File "/usr/share/msa/ui/mykui/decorators.py" in _inner
  31. 		return view(*args, **kwargs)
File "/usr/share/msa/ui/mykui/reports/views.py" in reports_ondemand
  38. 				if form.is_valid():
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/forms/forms.py" in is_valid
  124.         return self.is_bound and not bool(self.errors)
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/forms/forms.py" in _get_errors
  115.             self.full_clean()
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/forms/forms.py" in full_clean
  270.         self._clean_fields()
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/forms/forms.py" in _clean_fields
  287.                     value = field.clean(value)
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/forms/forms.py" in _clean_fields
  287.                     value = field.clean(value)
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/forms/fields.py" in clean
  153.         value = self.to_python(value)
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/forms/fields.py" in to_python
  437.         result = super(DateTimeField, self).to_python(value)
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/forms/fields.py" in to_python
  342.                     return self.strptime(value, format)
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/forms/fields.py" in to_python
  342.                     return self.strptime(value, format)
File "/usr/share/msa/jython/Lib/site-packages/Django-1.4.2-py2.5.egg/django/forms/fields.py" in strptime
  441.         return datetime.datetime.strptime(value, format)
File "/usr/share/msa/jython/Lib/datetime.py" in strptime
  1499.         return cls(*(_time.strptime(date_string, format))[0:6])

Exception Type: IllegalArgumentException at /reports/ondemand/Top_Incident_Types/
Exception Value: java.lang.IllegalArgumentException: Illegal pattern character 'f'

At 441, format = '%Y-%m-%d %H:%M:%S.%f'

The %f formatting character was introduced in Python 2.6, but it is not supported in Jython, even in the 2.7 alphas. http://bugs.jython.org/issue1964

I remember this code working fine in Django 1.4.1, but I cannot seem to find a commit that would have broken it during the timeframe between the 1.4.1 and 1.4.2 releases.

Change History (6)

comment:1 Changed 3 years ago by aaugustin

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This behavior was introduced by the fix for #9459.

comment:2 Changed 3 years ago by russellm

  • Triage Stage changed from Unreviewed to Design decision needed
  • Type changed from Uncategorized to Bug

Given that this is a known bug in Jython, I'm not sure what the right response is here. The %f is needed to fix the problem from #9459; the right solution would seem to be "Fix Jython", not "put in a workaround in Django".

comment:3 Changed 3 years ago by fvox13

I agree that Jython is the right place to put the fix. However, as it stands right now, our documentation is wrong, because it states that we are compatible with Jython 2.5, when we're not. Some mention of this bug should appear here: https://docs.djangoproject.com/en/1.4/howto/jython/ especially given how common DateTimeField usage is.

comment:4 Changed 2 years ago by aaugustin

  • Triage Stage changed from Design decision needed to Accepted

Accepting as a doc fix.

comment:5 Changed 2 years ago by timo

  • Component changed from Forms to Documentation

comment:6 Changed 2 years ago by timo

  • Resolution set to duplicate
  • Status changed from new to closed

Marking as a duplicate of #20517 which suggests documenting Jython issues on a wiki page. I've made a note of this issue on that ticket.

Note: See TracTickets for help on using tickets.
Back to Top