﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
12517	Mistake in example for django.db.models.get_prep_lookup()	django@…	nobody	"http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#django.db.models.get_prep_lookup

In the example, the return value for an exact lookup is wrapped in a list:

{{{
#!python
    def get_prep_lookup(self, lookup_type, value):
        # We only handle 'exact' and 'in'. All others are errors.
        if lookup_type == 'exact':
            return [self.get_prep_value(value)]
}}}

This then gets passed to the DB connection's compiler in get_db_prep_lookup, and seeing a list, does a typecast to ARRAY (in the case of Postgres).

I think the example should in fact return just the value, not wrapped in a list (also as per the default implementation of get_prep_lookup in the source):

{{{
#!python
    def get_prep_lookup(self, lookup_type, value):
        # We only handle 'exact' and 'in'. All others are errors.
        if lookup_type == 'exact':
            return self.get_prep_value(value)
}}}

By making this change to a custom field I have, the undesired typecast behaviour described above is avoided."		closed	Documentation	dev		fixed			Ready for checkin	1	0	0	0	0	0
