Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#681 closed defect (fixed)

get_in_bulk fails for PK columns other than "id"

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



class MwUser(meta.Model):
    user_id = meta.IntegerField(primary_key=True)

This fails:

from django.models.wps import mwusers


Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/django/utils/", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))
  File "/usr/lib/python2.4/site-packages/django/core/meta/", line 1364, in function_get_in_bulk
    obj_list = function_get_list(opts, klass, **kwargs)
  File "/usr/lib/python2.4/site-packages/django/core/meta/", line 1135, in function_get_list
    return list(function_get_iterator(opts, klass, **kwargs))
  File "/usr/lib/python2.4/site-packages/django/core/meta/", line 1118, in function_get_iterator
    cursor.execute("SELECT " + (kwargs.get('distinct') and "DISTINCT " or "") + ",".join(select) + sql, params)
  File "/usr/lib/python2.4/site-packages/django/core/db/", line 10, in execute
    result = self.cursor.execute(sql, params)
  File "/usr/lib/python2.4/site-packages/django/core/db/backends/", line 32, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python2.4/site-packages/MySQLdb/", line 95, in execute
    return self._execute(query, args)
  File "/usr/lib/python2.4/site-packages/MySQLdb/", line 114, in _execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.4/site-packages/MySQLdb/", line 33, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1054, "Unknown column '' in 'where clause'")

Change History (3)

comment:1 Changed 10 years ago by jdunck@…

OK, sorry; PK is integer, example should have been given:


comment:2 Changed 10 years ago by adrian

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

(In [991]) Fixed #681 -- get_in_bulk no longer assumes PK fields are called id. Also added unit tests to confirm. Thanks, Jeremy Dunck

comment:3 Changed 10 years ago by jdunck@…

Your responsiveness really is rediculous, Adrian. :)

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