Opened 7 years ago

Closed 7 years ago

#7383 closed (invalid)

MySql error "Truncated Incorrect Double Value" using extra()

Reported by: bcurtu Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I'm experiencing this error when I use the extra() function:

    def get_entrada(self,key):
        es=Entradilla.objects.extra(where=['%s=True'], params=[key])  

In this case, key variable contains the name of the object's attribute.
I'm working with django-trunk version 0.97-pre-SVN-7569 and MySQL 5.0.45

The stack trace i get is:

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/admin/engine/event/7/
Django Version: 0.97-pre-SVN-7569
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'autodesc.engine']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "/usr/lib64/python2.5/site-packages/django/core/handlers/base.py" in get_response
  82.                 response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib64/python2.5/site-packages/django/contrib/admin/views/decorators.py" in _checklogin
  62.             return view_func(request, *args, **kwargs)
File "/usr/lib64/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/usr/lib64/python2.5/site-packages/django/contrib/admin/views/main.py" in change_stage
  338.             new_object = manipulator.save(new_data)
File "/usr/lib64/python2.5/site-packages/django/db/models/manipulators.py" in save
  109.         new_object.save()
File "/home/bcm/ws/autodesc/../autodesc/engine/models.py" in save
  70.                 self.descripcion = self.descripcion + " " + self.get_entrada('salsa') 
File "/home/bcm/ws/autodesc/../autodesc/engine/models.py" in get_entrada
  115.         return es[0].frase  
File "/usr/lib64/python2.5/site-packages/django/db/models/query.py" in __getitem__
  129.             return list(qs)[0]
File "/usr/lib64/python2.5/site-packages/django/db/models/query.py" in __len__
  55.             self._result_cache.extend(list(self._iter))
File "/usr/lib64/python2.5/site-packages/django/db/models/query.py" in iterator
  162.         for row in self.query.results_iter():
File "/usr/lib64/python2.5/site-packages/django/db/models/sql/query.py" in results_iter
  200.         for rows in self.execute_sql(MULTI):
File "/usr/lib64/python2.5/site-packages/django/db/models/sql/query.py" in execute_sql
  1466.         cursor.execute(sql, params)
File "/usr/lib64/python2.5/site-packages/django/db/backends/util.py" in execute
  18.             return self.cursor.execute(sql, params)
File "/usr/lib64/python2.5/site-packages/MySQLdb/cursors.py" in execute
  165.         self._warning_check()
File "/usr/lib64/python2.5/site-packages/MySQLdb/cursors.py" in _warning_check
  80.                     warn(w[-1], self.Warning, 3)
File "/usr/lib64/python2.5/warnings.py" in warn
  62.                   globals)
File "/usr/lib64/python2.5/warnings.py" in warn_explicit
  102.         raise message

Exception Type: Warning at /admin/engine/event/7/
Exception Value: Truncated incorrect DOUBLE value: 'salsa'

Cheers

Change History (1)

comment:1 Changed 7 years ago by Karen Tracey <kmtracey@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

The quoting done by extra params= is not correct for column names in the database. The example here:

http://www.djangoproject.com/documentation/db-api/#extra-select-none-where-none-params-none-tables-none-order-by-none-select-params-none

shows it being using for the right-hand-side only, not the left. I think your get_entrada function should be more like:

def get_entrada(self,key):
        wherespec = '`%s`=True' % key
        es=Entradilla.objects.extra(where=[wherespec])  
Note: See TracTickets for help on using tickets.
Back to Top