Hi, I'm back to report that I have found the cause and a temporarily
solution to my problem.
First of all; thanks to Malcolm and Karen for trying to help me out,
even if I didn't give a lot of detail on the problem in the first
round. The reason was that I was frustrated and tired late in the
night when sending the first desperate help call.
> However, now that I look back at your original report, I notice that you
> didn't actually give a lot of details of the error. Just the final line
> of the exception, which is equivalent to saying "I'd like to report a
> car accident" and then not mentioning the location. You will have a full
> traceback there (if you're seeing this in Django's debug screen, switch
> to cut-and-paste view before trying to paste the traceback). It would be
> interesting to see the exact line the error occurred on and the type of
> exception that was raised. The int() function call is used both in
> floatformat() itself and as part of the Decimal() class, so it's not
> obvious which line if the problem.
OK, Malcolm, now I have spotted the _exact_ location of the "code
crash", and it is at the point where I send my SQL statement off to
pymssql and get it returned (the exact point is actually when it is
returned).
This is my code to pymssql:
cur = con.cursor()
cur.execute(str_query)
lst_result = cur.fetchall()
And the result returned in the variable lst_result is the following:
[(Decimal("27164771"), 27, 16, 7.77128, 9.2557200000000002, 2006,
'Quantum dynamics of a d-wave Josephson junction', 3, 30.0,
'000234546300030', 17.601243339253998, '@', 7)]
Do you notice the Decimal("27164771")? This is the ID of the record in
question and the value is stored as a longint in our MS SQL database.
It seems to me that when the Python renderer sees the Decimal() call,
it goes and fetches my OS locale, which calls for Swedish decimal
commas instead of US decimal points. After the results have been
returned the Django templates won't accept floats containing decimal
points, but it works with decimal commas.
If I remove the record ID from my SQL query templates works fine with
floats with decimal points. So I temporarily solved my problem by
removing the ID (I actually don't use it, it was just there just in
case). The reason my other view was working fine was because I wasn't
returning any record ID in that code.
So, after all I believe that the problem was introduced in some update
of the Django code that I fetched via the CVS during last weekend. (I
don't know why I couldn't revert.)
I'm a bit confused about the Django upgrade affecting this part,
because I believe that the call to pymssql goes unaffected outside of
the Django code. Could it be that this call has been returning a
Decimal all the time, but now something has been changed in Django so
that it sees the locale change generated by the Decimal()?
If I try to give you more detail about the problem, do you think you
can help me to get the (possible) problem fixed in the Django or
possibly my pymssql code?
Right now I running Django version 9532, pymssql 0.8.0, Python 2.5.2,
Apache 2.2 with mod_python.
I have pasted the traceback below. Please let me know if I can give
you more detail to solve this problem.
Thanks for any more help on this,
Ulf
----------------------------------------------
Traceback:
Environment:
Request Method: POST
Request URL: http://localhost/vr/isi/items/
Django Version: 1.1 pre-alpha SVN-9532
Python Version: 2.5.2
Installed Applications:
['vr.isi',
'vr.org',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.admindocs']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware')
Template error:
In template c:\web\vr\templates\isi\items\items.html, error at line
106
Caught an exception while rendering: invalid literal for int() with
base 10: ''
96 : </tr>
97 : <tr>
98 : <th> Number of publications analysed </th>
99 : <td>P</td>
100 : <th> {{ int_publications_count }} </th>
101 : <td> Not fractionalised </td>
102 : </tr>
103 : <tr>
104 : <th> Fractionalised number of publications
analysed </th>
105 : <td>P<sub>frac</sub></td>
106 : <th> {{ int_publications_count_frac|
floatformat }} </th>
107 : <td>Fractionalised based on the number of
author addresses</td>
108 : </tr>
109 : <tr>
110 : <th> Average number of citations per
publication and year </th>
111 : <td>c<sub>y</sub></td>
112 : <th> {{ flt_cy_average|floatformat }} </th>
113 : <td> Open citation window, self-citations
removed (based on author name matching)</td>
114 : </tr>
115 : <tr>
116 : <th> Share of publications cited above year
threshold {{ obj_config.flt_citation_significant_threshold }} </th>
Traceback:
File "C:\Program\Python25\lib\site-packages\django\core\handlers
\base.py" in get_response
86. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\web\vr\isi\views.py" in items_analysis
767. return render_to_response(template, locals())
File "C:\Program\Python25\lib\site-packages\django\shortcuts
\__init__.py" in render_to_response
18. return HttpResponse(loader.render_to_string(*args,
**kwargs), **httpresponse_kwargs)
File "C:\Program\Python25\lib\site-packages\django\template\loader.py"
in render_to_string
107. return t.render(context_instance)
File "C:\Program\Python25\lib\site-packages\django\template
\__init__.py" in render
176. return self.nodelist.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\__init__.py" in render
768. bits.append(self.render_node(node, context))
File "C:\Program\Python25\lib\site-packages\django\template\debug.py"
in render_node
71. result = node.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\loader_tags.py" in render
97. return compiled_parent.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\__init__.py" in render
176. return self.nodelist.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\__init__.py" in render
768. bits.append(self.render_node(node, context))
File "C:\Program\Python25\lib\site-packages\django\template\debug.py"
in render_node
71. result = node.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\loader_tags.py" in render
97. return compiled_parent.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\__init__.py" in render
176. return self.nodelist.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\__init__.py" in render
768. bits.append(self.render_node(node, context))
File "C:\Program\Python25\lib\site-packages\django\template\debug.py"
in render_node
71. result = node.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\loader_tags.py" in render
24. result = self.nodelist.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\__init__.py" in render
768. bits.append(self.render_node(node, context))
File "C:\Program\Python25\lib\site-packages\django\template\debug.py"
in render_node
71. result = node.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\defaulttags.py" in render
254. return self.nodelist_true.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\__init__.py" in render
768. bits.append(self.render_node(node, context))
File "C:\Program\Python25\lib\site-packages\django\template\debug.py"
in render_node
81. raise wrapped
Exception Type: TemplateSyntaxError at /vr/isi/items/
Exception Value: Caught an exception while rendering: invalid literal
for int() with base 10: ''
Original Traceback (most recent call last):
File "C:\Program\Python25\lib\site-packages\django\template
\debug.py", line 71, in render_node
result = node.render(context)
File "C:\Program\Python25\lib\site-packages\django\template
\debug.py", line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
File "C:\Program\Python25\lib\site-packages\django\template
\__init__.py", line 559, in resolve
new_obj = func(obj, *arg_vals)
File "C:\Program\Python25\lib\site-packages\django\template
\defaultfilters.py", line 170, in floatformat
exp = Decimal('1.0') / (Decimal(10) ** abs(p))
File "C:\Program\Python25\Lib\decimal.py", line 1155, in __div__
op2 = _WorkRep(other)
File "C:\Program\Python25\Lib\decimal.py", line 4676, in __init__
self.int = int(value._int)
ValueError: invalid literal for int() with base 10: ''
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---