Opened 9 years ago

Closed 9 years ago

Last modified 8 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:

Description

Given:

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

This fails:

from django.models.wps import mwusers
mwusers.get_in_bulk(['Wpsadmin'])

with:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/django/utils/functional.py", 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/__init__.py", 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/__init__.py", line 1135, in function_get_list
    return list(function_get_iterator(opts, klass, **kwargs))
  File "/usr/lib/python2.4/site-packages/django/core/meta/__init__.py", 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/base.py", line 10, in execute
    result = self.cursor.execute(sql, params)
  File "/usr/lib/python2.4/site-packages/django/core/db/backends/mysql.py", line 32, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 95, in execute
    return self._execute(query, args)
  File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 114, in _execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 33, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1054, "Unknown column 'mw_user.id' in 'where clause'")

Change History (3)

comment:1 Changed 9 years ago by jdunck@…

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

mwusers.get_in_bulk([1])

comment:2 Changed 9 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 9 years ago by jdunck@…

Your responsiveness really is rediculous, Adrian. :)

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